Skip to content

Instantly share code, notes, and snippets.

@kaievns
Created December 15, 2010 16:17
Show Gist options
  • Save kaievns/742181 to your computer and use it in GitHub Desktop.
Save kaievns/742181 to your computer and use it in GitHub Desktop.
// a simple custom wrapper
var Widget = new Class(Element, {
initialize: function(raw_element) {
// calling the Element's constructor
this.$super(raw_element, {
'class': 'my-widget'
});
},
// some other custom methods
});
var widget = new Widget(document.getElementById('my-element'));
// basically any time you create an instance of an `Element` class
// or it's subclass, RightJS will register the last instance as
// the default wrapper, so even if an element was already wrapped
// it will be rewrapped again, say like that
$('my-element'); // -> Element
new Widget($('my-element')._);
$('my-element'); // -> Widget
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment