Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Object.defineProperty(<some parameters...>)
- // Define the extend function
- Object.defineProperty(Element.prototype, 'extend', { value: function(namespace, object) {
- // Create the namespace and make sure on invocation the Element is bound
- Object.defineProperty(Element.prototype, namespace, { value: function() {
- var extended = Element.prototype[namespace].extended;
- for (var e in extended) {
- extended[e] = extended[e].bind(this);
- }
- return extended;
- }});
- this[namespace].extended = object;
- return this;
- }});
- // Extend the Element prototype with an attr function in
- // the namespace 'namespace' or ofcourse whatever function
- Element.prototype.extend('namespace',{
- attr: function(name, value) {
- if(arguments.length === 1) {
- return this.getAttribute(name);
- } else {
- this.setAttribute(name, value);
- return this;
- }
- }
- });
- document.querySelector('.a-css-class').namespace().attr('class')
- // returns 'a-css-class'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement