/** * @ fileoverview Javascript OO JS面向对象 */ /** * @overview function 形式 赋值需要用this */ function a(){ //属性 this.name=null; //方法 this.setName=function(name){ this.name=name; }; //方法 this.getName=function(){ return this.name; } } /** * Json 变量形式,注意json的格式 */ var b={ //属性 name:"greengnn", //方法 run:function(){ alert("start run"); }, //方法 sayHello:function(){ alert("hello world"); } } /** * function方式调用测试 */ var _p=new a(); _p.setName("greengnn"); alert(_p.getName()); alert(_p.name); /** * Json方式调用测试 */ b.name; b.run(); b.sayHello(); 两种建立方式和调用