1

I am getting not a function error from javascript.

This is part of my object that I define:

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

After that I create another object:

  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));
    }
}

I am getting following error:

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

Can someone advice what is the problem?

4
  • this.productConfig = new productConfig(); Commented Jan 14, 2016 at 12:46
  • Only if the OP were not following regular case conventions in JavaScript. Everywhere else, the OP seems to follow it though. @bla009 where is the code that is calling Product.ConfigurableSwatches.init? Commented Jan 14, 2016 at 12:58
  • can you add some working code forking from your code. Commented Jan 14, 2016 at 12:59
  • @CodeiSir that initializer is missing. I added it before Product.ConfigurableSwatches. Can you add your answer so I can mark it as correct answer. Commented Jan 14, 2016 at 13:22

1 Answer 1

1

The line this.productConfig = productConfig should be

this.productConfig = new productConfig()

to create a new Object with its prototypes

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.