oop - private and public methods in javascript -



oop - private and public methods in javascript -

how design objects in javascript public , private methods?

how access private method private_method api.get?

function api(){ function private_method(){ homecoming 'weeee'; } } api.prototype.get = function(){ // access "private_method" };

you can create self-executing function wraps private methods in function's scope.

// self-executing function var api = (function() { function api() {}; api.prototype.get = function() { // can phone call private_method. private_method(); } // accessible object created in scope. function private_method() { } homecoming api; })();

this method prevents unnecessary code beingness executed each time constructor called.

here's working fiddle: http://jsfiddle.net/7qm9h/

javascript oop

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -