Private variables with that method:


You can make private variables in the init method, for example. You just need to make getters and setters as well, i.e.

init: function() {   // Private var   var _div = $( div );   // Priviledged method accesses private var   this.getDiv = function () { return _div; }   this.setDiv = function (div) { _div = div; }   // other initialization stuff }

Downside is that the privileged getters and setters can’t be put in the prototype, i.e. they are created for each instance separately. Another issue is the overhead of closures in general.

Interesting Information about extending prototypes:

Reading files with javascript:

javascript private scope, maybe a good read:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s