Karl Tiedt:
“Have you ever found a widget that does almost *everything* you need, yet you still manage to find some small thing that needs to be done differently? Ever cringe at the thought of having to extend a widget to add 5 or 10 lines of code to it? In the past, thats what you had to do… well unless you were really gung-ho and wanted to write your own from scratch.”
It’s meant to be a cookie, so it’s meant to be short and sweet, but I might as well use this as an opportunity to build on that.
First of all, this will work with any class-type object that can accept a property and a node as its two parameters and not barf. Overall, the point of DojoML has always been prototyping. Being able to prototype a change to the way a widget (or any object) works inline is really nice.
Secondly, and as much as I say this, it doesn’t seem to get understood, this whole pattern is functionally equivalent to creating a function that:
- Creates a new instance of a widget
- Uses dojo.connect, or a direct override to change its functionalitty
- Returns that instance
In JavaScript, a constructor function can return whatever it wants, so you can use it as an adapter, which is totally possible here.