JavaScript Pattern Roundup – Issue 4

Due to the fact that most pattern categories have been added to the collection, future roundups will only come when there is significant amount of updates.

Juriy “kangax” Zaytsev has put very detailed research findings about named function expressions. As it says on the github site: In a nutshell, named function expressions are useful for one thing only — descriptive function names in debuggers and profilers. It has been added to Function Declarations.

Code reuse patterns discussed in Stoyan’s JavaScript Patterns have been added:

Classical Patterns (patterns that should generally be avoided)

  • The Default Pattern – create an object using the Parent() constructor and assign this object to the Child()’s prototype
  • Rent a Constructor – it borrows the parent constructor, passing the child object to be bound to this and also forwarding any arguments
  • Rent and Set Prototype – restricts object creation for a class to only one instance
  • Share the Prototype – restricts object creation for a class to only one instance
  • A Temporary Constructor – first borrow the constructor and then also set the child’s prototype to point to a new instance of the constructor
  • Klass – generally a pattern that should be avoided unless one is more comfortable with class than prototype

Preferred Patterns

Be Sociable, Share!

About Shi Chuan

I am a web developer.
This entry was posted in JavaScript and tagged . Bookmark the permalink.

2 Responses to JavaScript Pattern Roundup – Issue 4

  1. aaa says:

    俺觉得js还是不要搞什么模式好,为啥?js灵活啊,你却用一个个模式去套它?累不再说,没那必要……脚本还是灵活的脚本……

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>