I’m thinking of the following functionality:
$('.aclass').MyPluginInit()
$('.aclass').SomeMethodOfMine()
but how do we get from the first to the second line? In the ideal world, I’d be able to trap the exception generated in line 2 (when I attempt to invoke a method that doesn’t exist), loop through the set of objects that $('.aclass') represents and for each, look at a property (say, $this) that contains said method and was placed there by the call to .MyPluginInit(). I would then invoke the method.
the problem is I can’t trap the exception and find my way back to the object on which it was raised. the handler for window.onerror will tell me the url and line number that produced the exception but I can’t tie that to an object.
any thoughts on how else I could accomplish my raising of the dead (or never-born in this case)?
- ekkis
p.s. I did read Autovivification and Javascript, but what I’m asking is a bit different.
this is what I came up with: put the following function in some library you include before including plugins that use it:
then define your plugins like this:
then, having included the plugin you can do:
or even: