class instance interface abstract-class extends implements private protected public static const constructor super read-only friendly-method event |
Friendly-methodWhile ZNOW provides very good encapsulation to private and protected properties. There are many cases private and protected properties have to be called outside. One example is the callback function. A function is passed as an argument outside the object. To register a function as a friendly function, which can access private/protected attributes, you have just to add "this". var ClassA=Class({
foo:function(){
var _this=this;
document.body.addEventListener(
'click',
/*A function is passed as an argument.
To access private attribute,
the function is registered by "this"*/
this(function(){
alert(_this._a); //access private attribute
})
);
},
_a:1
});
|