I may be trying to do something I shouldn’t here, but I’d like Isomorphic’s take on it. I’m trying to override the Canvas.init method in such a way that whenever any Canvas in created in my application, it runs a piece of code. Specifically, I want every Canvas to check for two properties called “profileEnabled” and “profileProperties”, and if they’re found, to load the given properties from a set of user profile properties loaded when the application starts.
So I did this:
isc.Canvas.addMethods({
baseInit: isc.Canvas.init,
init: function() {
if (this.profileEnabled && isc.isAn.Array(this.profileProperties) && this.profileProperties.length>0)
for (var iProp=0;iProp<this.profileProperties.length;iProp++) {
if (this[this.profileProperties[iProp]])
alert(this.profileProperties[iProp]); // this is just a test line
}
this.baseInit(arguments);
}
});
As you might have guessed, this doesn’t work. My Canvases refuse to load, and I can’t even get the Developer Console to open with this bit of code in here. So, obviously my clever solution was less clever than I thought.
I realize this is dangerous and most likely foolish to try to play around with such fundamental bits of the SmartClient framework. Still, can I do it? How? I want to avoid having to individually override init() for every single Canvas subclass in my application (almost every Canvas loads a few initial properties from the user’s profile). So how could I do this generically without breaking SmartClient?