//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("唱歌");

 

相关文章:

猜你喜欢
  • 2021-08-01
  • 2022-12-23
  • 2022-01-01
  • 2021-12-04
  • 2021-12-04
相关资源
相似解决方案