var xyj = {
name: '孙悟空',
age: 1000,
gender: '男',
jieshao: function() {
return "姓名:" + this.name + "\n年龄:" + this.age + "\n性别:" + this.gender;
},
jieshao2: function(loc) {
return loc + ":\n" + "姓名:" + this.name + "\n年龄:" + this.age + "\n性别:" + this.gender;
}
};
var xyj2 = {
name: '猪八戒',
age: 800,
gender: '男',
}
// var intro = xyj.jieshao.call(xyj2);
// console.log(intro);
// var intro2 = xyj.jieshao2.call(xyj2, '高老庄');
// console.log(intro2);
var intro = xyj.jieshao.apply(xyj2);
console.log(intro);
intro = xyj.jieshao2.apply(xyj2, ['高老庄', ])//和call的惟一区别是用函数列表
console.log(intro);