like to ask if the external parenthises are really necessary? Like here:
incident.Controller = (...)` //see code block at the end of this question I dont think so. (at least the code works the same for me).
Also, I'd like to ask about the difference between the two snippets of code below.
The benefit writing the code below in a function (the first snippet below) is to scope things to myCompany.incident by using the "use strict" statement. Like below. But is this the only difference?
(and i would otherwise write it out as in the snippet beneath it)
myCompany.incident = (function(incident) {
"use strict";
incident.Contracts = {
onLoad: function() {
var controller =
new myCompany.incident.Controller(Xrm);
controller.load();
}
};
return incident;
}(myCompany.incident || {}));
I would otherwise (if not for "use strict";) write it out like this:
myCompany.incident = myCompany.incident || {};
myCompany.incident.Contracts = { onLoad: function() {
var controller = new myCompany.incident.Controller(Xrm);
controller.load();
}
};
I dont think "use strict;" is the only difference/consquence of the two snippets, which is the reason for this question.
Thanks, p.
/// <reference path="controller.js"/>
/*global myCompany: true*/
myCompany = window.myCompany || {};
myCompany.incident = (function(incident) {
"use strict";
incident.Contracts = {
onLoad: function() {
var controller =
new myCompany.incident.Controller(Xrm);
controller.load();
}
};
return incident;
}(myCompany.incident || {}));