Slide 11
Slide 11 text
var klass = $pvt("_" /* prefix */, {
// public method access to public variable
getPublicVariable: function() {
return this.publicVariable;
},
// public method access to private variable
getPrivatevariable: function() {
return _privateVariable;
},
// privateϝϯόΛࢀর͍ͯ͠ΔprivateϝιουΛݺͼग़͢public method
getPrivateMethodReferPrivateVariable: function() {
return _getPrivateVariable();
},
// publicϝϯόΛࢀর͍ͯ͠ΔprivateϝιουΛݺͼग़͢public method
getPrivateMethodReferPublicVariable: function() {
// ͜ͷ߹ίϯςΩετΛࢦఆ͠ͳ͍ͱ͍͚ͳ͍…
return _getPublicVariable.call(this);
},
// privateϝϯόʹΞΫηε͢Δprivate method
_getPrivateVariable: function() {
return _privateVariable;
},
// publicϝϯόʹΞΫηε͢Δprivate method
_getPublicVariable: function() {
return this.publicVariable;
},
// public variable
publicVariable: 1,
// private variable
_privateVariable: 2
});
Usage