0

Why doesn't my JavaScript pattern work? For example I try to call the function this.prepare.build(), but it doesn't works. It gives me this error:

this.prepare.build is not a function

<script>
$(function () {
    new $.Myfunction();
});
</script>


<script>
(function($) {

    'use strict';
    function Myfunction(options) {
        return new Myfunction.prototype.init(options);
    }

    Myfunction.fn = $.Myfunction.prototype = {
        init: function() {
            console.log('call: Myfunction.init')
            this.prepare.build();
        },
        prepare: function() {
            return {
                 build: function() {
                        console.log('call: Myfunction.prepare.build');
                 },
                 run: function() {
                        console.log('call: Myfunction.prepare.run');
                 }
            }
        }
    }
    Inviter.prototype.init.prototype = Inviter.prototype;
})(jQuery);
</script>
1
  • 3
    you need to call this.prepare().build() Commented Oct 10, 2015 at 11:54

1 Answer 1

1

Might as well answer the question. prepare is a function as is build, so you need to call both:

this.prepare().build() 
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.