日期:2014-05-16 浏览次数:20493 次
function Container(param) {
this.member = param; //public
var secret = 3; //private
function testPrivateMethod() { //private method
alert('private method!');
}
this.objectMethod = function testPublicObjectMethod(){ //public method
alert('this is a public Object method !');
};
}
function testObject(param) {
//alert(member); //member is not defined,直接在外部访问,就算是public变量也是不可见的,必须通过变量来访问
var myContainer = new Container(param);
alert(myContainer.member);
// myContainer.member = 'ccccc'; //通过对象修改public成员变量
// alert(myContainer.member);
myContainer.objectMethod(); //this定义的方法可见,var定义的方法不可见
}
Container.prototype.testPrototype = function() {
alert("this is a public method from prototype!");
};