0

When the following piece of JavaScript code runs in the browser, the exception "object is not a function" is thrown in the first line. Why is that? I can't find the error.

((function (getSettings) {
    tinyMceWysiwygSetup.prototype.getSettings = function (mode) {
        var oSettings = getSettings.call(this, mode);
        oSettings.extended_valid_elements = "article[class],section[class],input[placeholder|accept|alt|checked|disabled|maxlength|name|readonly|size|src|type|value|class|id]";
        return oSettings;
    };
})(tinyMceWysiwygSetup.prototype.getSettings));

Also, if I paste the above snipped in the Chrome Developer Tools JS console, no exception is thrown. This is a screenshot from the Chrome Debugger, when the exception is caught:

enter image description here

Erik
  • 11,944
  • 18
  • 87
  • 126
  • 5
    What's the code before that line? I bit it's something that returns a function object (hence calling the function). – Felix Kling Nov 04 '14 at 18:13
  • Not sure if that's the problem, but if `tinyMceWysiwygSetup.prototype.getSettings` is not defined previously, `getSettings.call` will throw (because `getSettings` will be undefined). – Oriol Nov 04 '14 at 18:13
  • The most likely cause is that the line before this code sample ends with an object (or a reference to an object) and the line is not terminated by a semicolon, causing `objectFromLastLine(function (getSettings) ... )`. Automatic semicolon insertion does not happen if the parser can validly read the next line of code as a continuation of the previous line. – apsillers Nov 04 '14 at 18:15
  • I ran your code with the argument changed to "moo" and `tinyMceWysiwygSetup.prototype.getSettings` changed to `getSettings`. It ran without errors, so you probably want to rewrite this to a function declaration and separate invocation instead of selfrunning declaration, so it's easier to debug. – Mike 'Pomax' Kamermans Nov 04 '14 at 18:16
  • See also [this question](http://stackoverflow.com/q/24067605/1048572) for an explanation – Bergi Nov 04 '14 at 18:36

0 Answers0