From: Robin B. <ro...@kn...> - 2001-09-18 18:11:06
|
On Tuesday 18 September 2001 19:58, Antoine Quint wrote: > node_list.item(i).hasOwnProperty('style') works great! Where did you > find info about this? The E262 is a PITA to read (it's targetted towards implementors) but it's the total spec, and contains everything. From what I understand, OO in E262 is completely prototype based. That is, a random string has the prototype of String, etc... Now you have this thing that is called the Object object, from which all other objects derive (I still haven't figured out how that derivation works, but perhaps someone here is expert enough in type-based oo to explain it kindly to me). Object has the hasOwnProperty method which is there to check for the presence of a property (what you get through accessors like getFoo()). So I guessed that it had to be available to all objects. > Also, this example: > > var props = ''; > for (p in element) { > props += p + ': ' + element[p] + "\n"; > } > alert(props); > > Looks great but I don't understand what it does, where is p coming from? This is a much more classical usage of E262. The 'in' is key here, it's an iterator over 'element''s properties. For every iteration, p is simply the name of the next property (which likely includes methods, as methods in E262 are simply executable properties). In turn, element[p] is the value corresponding to that property. You can also do that in your browser, I often use it to debug weird behaviours. Hey, it looks like I might be becoming an E262 expert. S**t, I hope news of that don't spread to the Perl community or I might just as well switch to Python as well ;-) -- _______________________________________________________________________ Robin Berjon <ro...@kn...> -- CTO k n o w s c a p e : // venture knowledge agency www.knowscape.com ----------------------------------------------------------------------- An eye for an eye will make the whole world blind. -- Mahatma Gandhi |