日期:2014-05-16 浏览次数:20473 次
1.function myclass(name){ 2. var str = "private string";//private field 3. function privatefn(){ //private method 4. alert(str); 5. }; 6. this.name = name; 7. this.pubfn = function(){ 8. privatefn(); //call private method 9. alert("myclass.pubfn"); 10. } 11.}
1.var obj = new myclass("123"); 2.var name = obj.name; //access public field 3.obj.pubfn(); //call public method
1.var myclass = { 2. name : "123", 3. pubfn : function(){ 4. alert("pubfn1 is called"); 5. } 6.};
1.function myclass(name){ 2. var str = "private string"; //private field 3. function privatefn(){ //private method 4. alert(str); 5. }; 6. this.name = name; 7. this.pubfn = function(){ 8. privatefn(); //call private method 9. alert("myclass.pubfn"); 10. } 11.}