0

I get an Typeerror in my javascript code when defining my functions:

TypeError: (intermediate value)(...) is not a function

The function is defined as:

;(function (factory) {
    if (typeof define === "function" && define.amd) {
        define(["knockout", "jquery", "jquery.ui.sortable"], factory);
    } else {
        factory(window.ko, jQuery);
    }
})(function (ko, $) {

    // Some code including a bindingHandlers... 

})();

This code is included in my .ascx (view) after the knockout include as:

What does the error mean and how can I track it down and fix it?

I introduce (and bind) my viewModel like this:

<script type="text/javascript">
    jQuery(document).ready(function ($) { 
    var client = new myServiceClient(<%:ModuleContext.ModuleId%>);
    client.getModel()
        .done(function (model) {
            var viewModel = new ViewModel(model, client);
            //$("#template-load").load("DesktopModules/BBWysSceneStacker/scene-template.html")
             //   .success(
                    ko.applyBindings(viewModel, document.getElementById("<%= BBWysSceneStacker.ClientID %>"))
             //   )
            ;
        })
        .fail(function (model) {
            alert("Error in getModel!");
        });
    });
</script> 
Asle G
  • 568
  • 7
  • 27
  • Related: http://stackoverflow.com/questions/23370269/jquery-autosize-plugin-error-intermediate-value-is-not-a-function – nemesv Dec 30 '14 at 10:51
  • not sure but at the end you are missing a `)` closing that should be something like : `})());` – Jai Dec 30 '14 at 10:55
  • Thanks Jai, but which "(" is the missing ")" supposed to accommodate? – Asle G Dec 30 '14 at 11:05

1 Answers1

0

No need to run function second time.

;(function (factory) {
    if (typeof define === "function" && define.amd) {
        define(["knockout", "jquery", "jquery.ui.sortable"], factory);
    } else {
        factory(window.ko, jQuery);
    }
})(function (ko, $) {
    console.log('factory working');
});
  • 1
    I updated the solution. In your topic example you have one extra call of the function. Without it should work – Vitalii Del Vorobioff Dec 30 '14 at 11:28
  • Thanx, Vitalii. If I follow your example the error message go away but is replaced with an error on a jQuery.load function I call before I do the binding… "TypeError: $(...).load(...).success is not a function" – Asle G Dec 30 '14 at 11:38
  • Can you show snippet with jQuery.load() calling? More precisely, where it placed in? – Vitalii Del Vorobioff Dec 30 '14 at 11:47
  • I have added some info in the main question. However i removed the load to investigate further: the error message went away, but the code does not function. I guess there is some basic understanding I´m lacking here... – Asle G Dec 30 '14 at 13:51
  • Do I need to put the (function (ko, $) {…} around all my bindingHandlers perhaps? – Asle G Dec 30 '14 at 13:54
  • Sorry, there is no enougth information to give the right advise. – Vitalii Del Vorobioff Dec 31 '14 at 09:03