visitFunction错误是什么意思?

时间:2012-12-09 03:19:49

标签: javascript node.js express pug

运行Node.js@0.8.15 + Express@3.0.4 + Jade@0.27.7 + Stylus@0.31.0。 由于某种原因得到以下错误。有人知道这意味着什么吗?

我认为我没有做任何奇怪的事情。当我这样做时会发生这种情况:res.render(view, response);

Property 'visitFunction' of object #<Object> is not a function
    at Object.Compiler.visitNode (/app/node_modules/jade/lib/compiler.js:176:32)
    at Object.Compiler.visit (/app/node_modules/jade/lib/compiler.js:161:10)
    at Object.Compiler.visitBlock (/app/node_modules/jade/lib/compiler.js:253:12)
    at Object.Compiler.visitNode (/app/node_modules/jade/lib/compiler.js:176:32)
    at Object.Compiler.visit (/app/node_modules/jade/lib/compiler.js:161:10)
    at Object.Compiler.compile (/app/node_modules/jade/lib/compiler.js:78:10)
    at parse (/app/node_modules/jade/lib/jade.js:101:23)
    at Object.exports.compile (/app/node_modules/jade/lib/jade.js:163:9)
    at Object.exports.render (/app/node_modules/jade/lib/jade.js:215:17)
    at View.exports.renderFile [as engine] (/app/node_modules/jade/lib/jade.js:243:13)

1 个答案:

答案 0 :(得分:6)

您可能会收到该错误的原因之一是您将新属性(通常是方法)添加到Object.prototype

实施例:

Object.prototype.someNewMethod = function (value1, value2) {
    // ... perform some operations
    return this;
};

对于快递项目,不建议在问题#1033中说明向Object添加新属性的方式。 enumerable应与[{1}}设置为false一起使用。

使用Object扩展Object.defineProperty的示例

Object.defineProperty(
    Object.prototype, 
    'someNewMethod',
    {
        writable : false,
        // Will not show up in enumerable properties (including for-in loop).
        enumerable : false, 
        configurable : false,
        value : function (value1, value2) {
            // ... perform some operations
            return this;
        }
    }
);

我遇到了完全相同的问题,并使用Object.definePropertyenumerable:false来定义解决此问题的新属性。

我希望这会有所帮助。

相关问题