I have the following code (trucated for clarity):
if ( typeof CPM == "undefined" || !CPM) {var CPM={};}
(function(){
CPM.process = {
createStyles: function() {
//Do style processing
alert("processing styles");
},
createClasses = {
//Do style processing
alert("processing classes");
},
init: function(){CPM.process.createStyles()}
};
})();
init is a convention used in the company and must be there for other reasons. What I am trying to avoid is an additional function call for init. Is there an alternative way to write the same init and avoid creation of the function context? Like:
init: CPM.process.createStyles
The above fails, but am trying to see if there is any other way of achieving the optimization
Setting
init: CPM.process.createStylesdirectly fails becauseCPM.processisn’t defined yet at the point of theinitkey assignment. You need to build your object in two steps:Or you can use an external function definition and assign it to both keys: