>I wanted to provide this functionality to all table cells in the table.
>I thought this would be a good use of the prototype functionality in
>Javascript.  It seems like I can't get it to work.  Here's the code:

Extending the DOM is not the most effective means of doing this. For one
thing it won't work in IE7 or IE6, for another it is generally frowned upon
in the JavaScript community as a bad practice. There are people who do it,
to be certain, and there are libraries that do it as well (thought these
libraries are moving away from the practice). If I were you I would do
something more like this:

Board var pick = document.getElementById('pick2');
               pick.innerHTML = 'HELLO';

              tableFunction = function(){


 if(!document.getElementById('div' + i)){


 if(document.getElementById('suggbox')){

 this.removeChild(document.getElementById('suggbox'));
                                                               }


                                                               var mydiv =
document.createElement('div');
                                                               var myInput =
document.createElement('input');

 mydiv.setAttribute('id', 'div' + i);

 myInput.setAttribute('type', 'text');

 //myInput.prototype = SuggestionList(i);

 myInput.setAttribute('id', 'text' + i);

 myInput.style.size = 1;

 mydiv.appendChild(myInput);

 this.appendChild(mydiv);

 //myInput.addEventListener('keyup', searchDB(this.value,
2) ,false);
                                                       }
                                               }
//BIG CHANGE HERE
               var tableCells = querySelectorAll('#Board td'); //<- Use a
javascript library here
var i = tableCells.length;
while(i>=0){
tableCells[i].addEventListener('click',tableFunction,false);
i-=1;
}



On Mon, Jun 13, 2011 at 6:26 AM, Peter van der Zee <[email protected]>wrote:

> On Mon, Jun 13, 2011 at 12:43 PM, radiate <[email protected]> wrote:
> > Hi Peter,
> >
> > Thanks for your response.  For clarification purposes, it sounds like
> > you are saying I extended the child, which in this case was pick.  Are
> > you saying that if I were to "fix" this I would've extended the HTML
> > element that pick was derived from (the parent)?
>
> Yes. That's how you "extend" objects through prototype (in js);
> through the parent. Whenever you add a method to that prototype, all
> of its instances will also have that method (unless overridden).
>
> >
> > Also, it sounds like from your last paragraph that extending DOM
> > Elements is not typical practice.  So (and please excuse my
> > terminology), OOP in Javascript is really about data-handling/data-
> > processing for the most part.  Once the data is derived as desired it
> > then is outputted using built-in DOM functions (eg. appendChild,
> > innerHTML, etc)?
>
> No, not exactly. When you created the object, it's perfectly fine. But
> objects that are created in the DOM, like html objects, are called
> "host objects". Because they are created and governed by the host and
> not by you. The rules for these host objects can differ from what's
> normal in js. So you should do it with your own objects and stay away
> from these host objects. That means no extending HTMLDOMElement or
> whatever these super constructors are called.
>
> Also, OOP in js is not "about anything"... it's just a tool in the
> language. And everything in js is an object, so the name is kind of
> confusing anyways :) Just use prototype to create an architecture or
> make stuff easier for yourself. Stay away from DOM elements or the
> global Object object.
>
> - peter
>
> --
> 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