0

I'm using this syntax for my class creation (jQuery):

$.myClass = function() {}
$.myClass.prototype = {
    init: function() {
        console.log('initializing');
    },
    someFunc: function() = {
        console.log('some function is being called');
    }
}

When I call

var myClassObj = new $.myClass();

My init() function isn't being called, I have to call it manually. How do I edit my class's default initialization function instead of creating a separate one?

3
  • 3
    $.myClass = function() {this.init();} Commented Jan 18, 2014 at 2:55
  • Oh my god thank you. I'm dumb. Commented Jan 18, 2014 at 2:56
  • 1
    JSHINT or JSLINT is your friend. Commented Jan 18, 2014 at 3:09

1 Answer 1

1

You missed this -

$.myClass = function() 
    {
      this.init();
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thats exactly it. Durr. Thanks a bunch!

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.