private variables in javascript
(function(window){
//private variables
var name = "test";
var pieAGSI = function(){};
// get variable
pieAGSI.prototype.getName = function(){
return name;
};
// update variable
pieAGSI.prototype.setName = function(str){
name = str;
};
window.pieAGSI = pieAGSI;
})(window);
// test
var test = new pieAGSI();
document.write('<br>test.getName(): ' + test.getName()+"<br>");
评论
发表评论