首页 > Web开发 > 详细

js中对象继承的冒充方法

时间:2018-06-25 14:44:14      阅读:134      评论:0      收藏:0      [点我收藏+]
function Parent(name){
    this.name = name;
    this.sayName  = function(){
       console.log(this.name); 
   }
}

function Son(name,password){
  this.method = Parent;
  this.method(name);
  this.show = function(){
       console.log(this.name+‘ : ‘+this.password)  
   }    
  delete this.method;
}

var son1 = new Son(‘zhangsan‘,‘123456‘);
son1.show();

这种继承方式和原型链继承不一样,

这个是偷换了this的指向

js中对象继承的冒充方法

原文:https://www.cnblogs.com/jokes/p/9223797.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!