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: "&gt;", 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
Object.extend(..., options || {}) // Extend the object created about
with the name/value pairs in options, or not, if no options have been
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 
For more options, visit this group at 

Reply via email to