function people(word){
this.word = word;
this.say = function(){
console.log(this.word);
}
this.capacity = function(){
return this.say;
}
}
var p = new people('Hello World');
var res = p.capacity();
console.log(res)//ƒ (){console.log(this.word);}
console.log(res())//undefined
如上带吗,我new了一个people,返回的res 是一个function
但是为什么 我执行这个res为undefined,求解,我想的应该打印出来 hello world
如果改成这样呢
function people(word){
this.word = word;
this.say = function(){
console.log(this.word);
}()
this.capacity = function(){
return this.say;
}
}
var p = new people('Hello World');
var res = p.capacity(); //undefined
为什么res是undefined
jeck猫
相关分类