Could you please tell how to add a new method to Dojo?
It works for me, but only for NodeList:
dojo.extend(dojo.NodeList, {
foo: function() {
alert(1)
}
});
dojo.byId("foo").foo();
But, i need for Element:
dojo.byId("id").myMethod();
The
dojo.byIdfunction is just an alias fordocument.getElementById. Therefore it returns a vanilla domNode, and what you suggest would be adding a new method to Element, not Dojo.Dojo intentionally doesn’t change Element, because it’s considered bad practice to do so by some (it may collide with other frameworks, for example).
If you want to do it, you can add functions to Element’s prototype:
Then you can do: