Also you cannot use the class keyword because it's reserved in javascript, you'll have to use className or 'class' between quotes in the objectliteral.
There is a known bug in IE8 with creating elements with for example the Element constructor. In this case adding the classname with Element.addClassName works fine. On Wed, Sep 1, 2010 at 10:51 AM, Richard Quadling <rquadl...@gmail.com>wrote: > On 31 August 2010 19:20, kstubs <kst...@gmail.com> wrote: > > Thanks Richard for your answer on this! Question regarding this: > > > >> Object.extend(..., options || {}) // Extend the object created about > > > > Is it necessary to || {} (empty object) so as to not break the > > Object.extend in the event that options is null? > > > > Karl.. > > > > > > On Aug 31, 10:19 am, Richard Quadling <rquadl...@gmail.com> wrote: > >> On 31 August 2010 17:49, kstubs <kst...@gmail.com> wrote: > >> > >> > >> > >> > >> > >> > Hello, > >> > Full credit to: Matthew Foster for the code below. I'd like an > >> > explanation of the below. I'm having some troubles with Object extend > >> > and would like a better explanation of the magic that occurs below. > >> > >> > $C = function(name, options) { > >> > return Element.extend(Object.extend(document.createElement(name || > >> > "div"), options || {})); > >> > } > >> > >> > Sample use: > >> > var next = $C("td", { innerHTML: ">", className: "next" }); > >> > >> > So how are the properties innerHTML and className morphed on to this > >> > new td element? > >> > >> > Thanks, > >> > Karl.. > >> > >> Object.extend takes a set of name/value pairs and applies them to > >> whatever object it is extending. > >> > >> So, innerHTML and className, both properties of the DOM element TD, > >> get assigned by Object.extend. > >> > >> Taking the code inside out ... > >> > >> document.createElement(name || "div") // Create an element based of > >> the type defined by the value of name or a div, if no name is > >> supplied. > >> Object.extend(..., options || {}) // Extend the object created about > >> with the name/value pairs in options, or not, if no options have been > >> supplied. > >> Element.extend(...) // Same as $(...); > >> > >> Hope that helps. > >> > >> -- > >> Richard Quadling > >> Twitter : EE : Zend > >> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY > > > > -- > > You received this message because you are subscribed to the Google Groups > "Prototype & script.aculo.us" group. > > To post to this group, send email to > prototype-scriptacul...@googlegroups.com. > > To unsubscribe from this group, send email to > prototype-scriptaculous+unsubscr...@googlegroups.com<prototype-scriptaculous%2bunsubscr...@googlegroups.com> > . > > For more options, visit this group at > http://groups.google.com/group/prototype-scriptaculous?hl=en. > > > > > > The Object.extend code doesn't validate the options. So, if null is > supplied, this would result in an 'undefined' error. > > Considering that in most cases you'd be extending an object with > something, rather than simply subclassing it with no additional > properties/methods, then the code is tuned to the most common use > case. > > Using 'options || {}' simply turns the code into a common form. > > > -- > Richard Quadling > Twitter : EE : Zend > @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY > > -- > You received this message because you are subscribed to the Google Groups > "Prototype & script.aculo.us" group. > To post to this group, send email to > prototype-scriptacul...@googlegroups.com. > To unsubscribe from this group, send email to > prototype-scriptaculous+unsubscr...@googlegroups.com<prototype-scriptaculous%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/prototype-scriptaculous?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.