var range = {};
range.methods = {
includes : function(){
return this;
},
print:function(){
console.log(this)
//return this
}
}
console.log(range.methods.includes())
//
console.log(range.methods.print())
打印的结果是这样的:
Object { includes=function(), print=function()}
Object { includes=function(), print=function()}
undefined
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
最后一个undefined是你运行的
console.log(range.methods.print())的结果range.methods.print()函数返回值为undefined
函数
print返回的是undefined,你把return this注释掉了。第二个Object是console.log(this)打印出来的。你print函数都console了,你直接调用就行了,不用再console函数。最后一个undefined是print函数的返回值