> Switch to DOM tab in Firebug (or Chrome Dev Tools) and select the
> table cell element, then switch to console tab and type:
>> $0.__proto__
>
> This will give you the name of the object that you should extend. E.g.
> if __proto__ returns HTMLTableCellElement object, then you can add
> createtextbox() method to all table cell elements like this:
>
> HTMLTableCellElement.prototype.createtextbox = function() {
>   // place your code here
> }

Actually, this will work only in Chrome Dev Tools, I'm not sure how to
get the name of __proto__ object in Firebug.

> And do web application developers typically use prototype to extend
> functionality of standard HTML elements?

Extending core objects such as Array, String or Element is considered
to be a bad practice if your code is going to be executed in
environments that you don't control.

Let's say you have written a framework that will be included on
thousands of websites. The framework extends core Array object with
method isInArray() that returns either true or false:

Array.prototype.isInArray = function(element) {
  for (var i=0; i<this.length; i++) {
    if (this[i] === element) {
      return true;
    }
  }
  return false;
}

Your code is going to break if following conditions are met:
- there is another framework included on the website
- the second framework also extends core Array object with isInArray() method
- the values returned by the isInArray() from second framework differ
from the values from your framework (e.g. element position in array is
returned instead of true/false)

-- 
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