Slides from Ajax Experience 2009. In this session:
- Object creation patterns
- Code reuse patterns
- Functional patterns
- More on object creation
- Design patterns
Some example patterns: object creation with literals and constructos, prototypes, inheritance and other code reuse patterns, lazy definition, callbacks, singleton, factory, classical and prototypal inheritance, namespaces, chaining, modules, static methods, private and privileged members
For more information, see:
http://jspatterns.com
My column in the JavaScript Magazine (http://jsmag.com)
Blog: http://phpied.com
24. Example: borrowing from Array
function f() {
var args = [].slice.call(arguments, 1, 3);
return args;
}
>>> f(1, 2, 3, 4, 5, 6)
2,3
[].slice.call
can also be
Array.prototype.slice.call
25. Inheritance by copying properties
function extend(parent, child) {
var i, child = child || {};
for (i in parent) {
child[i] = parent[i];
}
return child;
}