【发布时间】:2017-08-08 01:24:05
【问题描述】:
我在 JS 中创建了如下对象:
function test(){
this.testParam1 = "add";
this.tstMethod = function(){
console.log("Hello") ;
};
}
var testObj = new test();
console.log(assignTest.tstMethod()); ---> it prints value as undefined
console.log(assignTest.tstMethod); ----> it prints the function
谁能解释一下为什么我们不能调用tstMethod作为函数?
【问题讨论】:
-
但是你确实将它作为一个函数调用...
-
assignTest到底是什么? -
抱歉,我在从本地复制粘贴时错过了将 assignTest 更新为 testObj。
标签: javascript function object