![](/img/trans.png)
[英]console.log() an object does not log the method added via prototype in node js console. Or how to print the prototypes also?
[英]Use console.log() to print the method of an object
我正在尝试获取以下内容以打印出-1
,但它只是显示该功能。
function Builder(first, second) {
this.first = first;
this.second = second;
this.equation = function(){
return this.first - this.second;
};
}
var test = new Builder(2,3);
console.log(test.equation);
由于方程式是一种方法,因此需要在其后加上括号以调用该方法。
function Builder(first, second) {
this.first = first;
this.second = second;
this.equation = function(){
return this.first - this.second;
};
}
var test = new Builder(2,3);
console.log(test.equation());
您必须使用如下括号来调用该函数:
console.log(test.equation());
尝试
console.log(test.equation());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.