I think a better way of doing it rather than augmenting the prototype
is create your own function/object that is a delegate. I guess
something like:

var elementDisabled = function(){
  return this.hasClass('disabled');
}

And then call it by doing elementDisabled.call(myEl); Or you can even
just have the funciton take the element. Augmenting the built-in
prototypes usually doesn't turn out too well.

------------------------
Gary Katsevman
Computer Science Undergraduate
Northeastern University
gkatsev.com



On Sun, Mar 20, 2011 at 15:17, Jarek Foksa <[email protected]> wrote:
> I do a lot of operations on objects retrieved by querySelector() and
> simillar DOM methods, so I thought it would be nice to extend the
> built-in Element object with some useful methods and properties.
>
> So far I didn't have any problems when adding new methods to
> prototypes, but the things are not so obvious to me when I'm trying to
> add new properties.
>
> For example, I would like to add Element.prototype.disabled property
> that would be set to true if the given element has class "disabled"
> and to false otherwise. My first thought was to alter the constructor
> function, but it's not feasible in this case because it's a built-in
> object. Another (probably silly) idea was to do this:
>
> Element.prototype.disabled = (function() {
>   if (this.hasClass('disabled') {
>     return true;
>  } else {
>     return false;
>  }
> })();
>
> which didn't work as well.
>
> Could you give me some hints what is the proper way to achieve may goal?
>
> Thanks in advance for any help!
>
> --
> To view archived discussions from the original JSMentors Mailman list: 
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here: 
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to