开发者

Why would Dojo 1.6 fail to properly load javascript file in IE8 using dojo.require?

开发者 https://www.devze.com 2023-03-23 03:45 出处:网络
The following code worked with Dojo 1.5 in Firefox and Internet Explorer 8. With Dojo 1.6, it still works in Firefox, but does not work in IE8.

The following code worked with Dojo 1.5 in Firefox and Internet Explorer 8.

With Dojo 1.6, it still works in Firefox, but does not work in IE8.

I get an Object doesn't support this property or method error when wrappingFunctionInPlainJsFile() is called.

HTML page:

<div dojoType="widget.MyCustomWidget"></div>

In widget/MyCustomWidget.js

dojo.provide("widget.MyCustomWidget");

dojo.require("js.plainJsFile");

dojo.declare("widget.MyCustomWidget", [dijit._Widget, dijit._Templated],  {
    ...

    // this gets called when the widget is clicked on in the UI
    run: function() {
        wrappingFunctionInPlainJsFile();
    },

    ...

});

In js/plainJsFile.js

dojo.provide("js.plainJsFile");

function someFunction() {
}

function wrappingFunctionInPlainJsFile(){
    new someFunction();
}

Any ideas on what I am doing wrong would be greatly appreciated.

开发者_开发问答

Note: If I import the plainJsFile.js directly on the HTML page instead of using dojo.require then I have no problems.


I believe that the purpose of the dojo.require system to break your code up into modules where those modules aren't just arbitrary chunks of js, but dojo.declare'd objects. When you write dojo.provide("js.plainJsFile"), by convention I'd expect there to be an global object called "js" which had a property "plainJsFile". See the code example on this page.

I actually use dojo.require the way that you do, ignoring the convention I'm describing, and it works just fine -- in firefox. IE won't swallow it though. IE will behave if all the required js files are compressed into a single file (which you mentioned solves your problem).

So, basically, I think that IE is less flexible about scope while dojo.require is doing its thing, and you putting function declarations in a "module" like that is breaking things. Try going with the convention and see if that helps.


I tried the dojo mailing list and got a fix courtesy of Karl Tiedt.

See here: http://dojo-toolkit.33424.n3.nabble.com/Why-would-Dojo-1-6-fail-to-properly-load-javascript-file-in-IE8-using-dojo-require-td3204800.html#a3204894

Copy/paste of solution.

"Its an IE quirk....

dojo.provide("js.plainJsFile");

(function() {
 function someFunction()

 wrappingFunctionInPlainJsFile = function() {
    new someFunction();
 }
})();

should work... I always use my name spaces though and do it this way

dojo.provide("js.plainJsFile");

(function(pjsf) {

  pjsf.someFunction = function()

  pjsf.wrappingFunctionInPlainJsFile = function(){
    new someFunction();
  }
})(js.plainJsFile);

"

Note: I tried the above solution and it worked for me in IE8 and Firefox.

0

精彩评论

暂无评论...
验证码 换一张
取 消