MooTools Tip: Class.toElement
Many of you may not know of a feature that's baked into MooTools' Class internals: Class.toElement. Class.toElement allows you to pass the $ (or document.id) method an instance of your class and the instance will be treated as an element.
The MooTools Class.toElement Usage
/* baking into the class */
var myClass = new Class({
initialize: function(container,options) {
this.container = $(container);
},
// .. lots more methods //
toElement: function() {
return this.container;
}
});
/* usage */
var mc = new MyClass('wrapper');
$(mc).fade('out'); //fades the container out
This isn't a groundbreaking piece of code but it's just another example of the flexibility that MooTools affords its developers. Happy coding!
If you follow me on Twitter, you know that I've been working on a super top secret mobile application using Appcelerator Titanium. The experience has been great: using JavaScript to create easy to write, easy to test, native mobile apps has been fun. My...
Chances are that any Web designers using our Ghostlab browser testing app, which allows seamless testing across all devices simultaneously, will have worked with responsive design in some shape or form. And as today's websites and devices become ever more varied, a plethora of responsive images...
Events play a huge role in JavaScript. I can't name one website I've created in the past two years that hasn't used JavaScript event handling on some level. Ask yourself: how often do I inject elements into the DOM and not add an...
I've always been intrigued by recognition software because I cannot imagine the logic that goes into all of the algorithms. Whether it's voice, face, or other types of detection, people look and sound so different, pictures are shot differently, and from different angles, I...
Haven’t noticed this wonderful tiny yet so useful method before. Thanks for bringing this up :)
i was actually just reading about this today.
it seems often times the method is used to create the element that gets returned as well, in which case its important to make sure the method doesn’t re-define the element it returns.
Hey, that’s a useful thing! Didn’t know this before, THX for sharing!