对于下面的代码,在Javascript中,我得到了输出:窗口
var name = "The Window";
var object = {
name : "My Object",
getNameFunc : function(){
return function(){
return this.name;
};
}
};
console.log(object.getNameFunc()());
但是对于Node.js,我得到了下面的输出:未定义
我很困惑,Nod
当发生正常异常时,会输出如下堆栈跟踪:
util.js:38
case '%s': return String(args[i++]);
^
TypeError: Cannot convert object to primitive value
at String (unknown source)
at util.js:38:25
at String.replace (native)
at Object.<anonymous> (util.js:35:23)
at Ob
好的,所以我创建了一个测试项目来展示这个错误。错误是Node无法在我的另一个对象中找到我的getStr函数。
这是代码:
test.js
var Another = require('./another.js');
var Other = require('./other.js');
var otherStr = Other.getStr();
console.log(otherStr);
other.js
var Another = require('./another.js');
var str = Another.getStr();
我所拥有的是一个简单的呈现函数,有一些条件。
class AwesomeTestClass {
constructor() { /* constructor stuff */ }
reder() {
let OUT = (<Text> basic text 1 </Text>);
if (someCondition) {
OUT += (<Text> add some condition text </Text>);
} else {
OUT += (<Text> add ot