//js面相对象编程 //定义constructor构造方法 function myFn(name,sex){ this.name = name; this.sex = sex; } //用prototype追加属性方法 myFn.prototype.getName = function(inter){ console.log(this.name); console.log("兴趣:" + inter); return this.name; } //实例化myFn var newMy = new myFn(); newMy.name = "黄晓明"; newMy.sex = "男"; newMy.getName("唱歌");
时间: 2024-10-09 22:52:26