<html> <head> <script type="text/javascript"> function People(name){ var isSingle = 'youl';//构造函数的私有属性 this.name = name;//公共属性 var queryIsSingle = function(sex){ if (sex == '1'){ return true; } else if(sex == '2'){ return false; } }//私有方法 this.getIsSingle = function(sex){ return queryIsSingle() ? 'boy' : 'gril'; }//公共方法 } var p = new People('susan'); document.write(p.name); People.prototype.age = 10;//原形属性 People.prototype.sayHi = function(){ return 'Hello ' + this.name; };//原形方法 var sayStr = p.sayHi(); alert(sayStr); document.write(p.age); People.make = function(tool){ if ('铁' == tool){ document.write('锅'); } else if ('金' == tool){ document.write('戒指'); } }//静态方法 People.make('铁'); </script> </head> <body> </body> </html>
浙公网安备 33010602011771号