Buddy’s Blog | Art, design, code, and business

Jan/10

7

More code reuse patterns in YUI3

About the Author: Stoyan Stefanov (@stoyanstefanov) is a front-end engineer at Yahoo! Search. He is also the architect of YSlow 2.0, co-creator of the smush.it image optimizer, speaker and technical writer. His latest book is called Object-Oriented JavaScript.

This post is a follow-up to the article “Inheritance patterns in YUI3″ and dives deeper into the YUI3 APIs showing more patterns for code reuse. The Gang of Four book advocates that we should “prefer object composition to class inheritance”. And in fact, inheritance is sometimes used as a workaround in strongly typed languages where the signature of an object or a class needs to be fixed at compile time. JavaScript is loosely typed and objects can be composed, mixed and augmented at any time.
Augmenting objects
In real-life JavaScript, it’s rare that you would have to setup deep inheritance chains. Often you may only want to augment an existing object (or a constructor) with the members of another, without necessarily forming a parent-child relationship…

Share and Enjoy:
  • email
  • Add to favorites
  • Digg
  • del.icio.us
  • LinkedIn
  • Google Bookmarks
  • Yahoo! Bookmarks
  • Facebook
  • MySpace
  • Live
  • Twitter
  • Technorati
  • StumbleUpon

RSS Feed

<<

>>