js apply call

function jone(name,age,work){
  this.name=name;
  this.age=age;
  this.work=work;
  this.say=function(msg){
    alert(msg+",我叫"+this.name+",我今年"+this.age+"岁,我是"+this.work)
  }
}
var jack={
  name:"jack",
  age:'24',
  work:"学生"
}
var pet=new jone();

pet.say.apply(jack,["欢迎您"]) // alert => 欢迎你, jack 24 学生

// pet.say.call(jack, "欢迎您") // 返回同上
console.log(this.name) // undefined

posted @ 2017-10-25 13:52  prolog  阅读(84)  评论(0编辑  收藏  举报