未捕获的TypeError不是函数 - 带有原型的javascript类

时间:2016-01-14 12:45:00

标签: javascript prototype

我从javascript中得不到函数错误。

这是我定义的对象的一部分:

Product.Config.prototype.configureSubscribe = function(funct)
{
    this.configureObservers.push(funct);
};

之后我创建了另一个对象:

  Product.ConfigurableSwatches = Class.create();
    Product.ConfigurableSwatches.prototype = {
    initialize: function(productConfig, config) {
            // redefine some default options if configured
            if (config && typeof(config) == 'object') {
                this.setConfig(config);
            }
            this.productConfig = productConfig;
            // Store configurable attribute data
            var attributes = [];
            for (var i in productConfig.config.attributes) {
                attributes.push(productConfig.config.attributes[i]);
            }
            this.configurableAttributes = attributes;
            // Run it
            this.run();
            return this;
        },
    run: function() {
        // HERE IT BREAKS
        this.productConfig.configureSubscribe(this.onSelectChange.bind(this));
    }
}

我收到以下错误:

Uncaught TypeError: this.productConfig.configureSubscribe is not a function

有人可以建议问题是什么吗?

1 个答案:

答案 0 :(得分:1)

number_format()应为

// Will round your number to 2 decimals with a . as decimal character
number_format($someNumber, 2, ",", ".");

创建一个带有原型的新对象