Skip to content
Myr

oo.js

This file

Path

lib/support/oo.js

93 lines · 2.3 KiB · JavaScript

Last changed by

Updated js-oo to 1.1.0 for mixins etcvisionmediabefore adoption37948d8

History of this file

Take it

The walk stopped after 200 commits: lines older than dd76816 point at it.

Added Collection#reject()visionmediabefore adoptiondd76816

lines 1–24why, one step back
1
2// OO - Class - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3// Based on http://ejohn.org/blog/simple-javascript-inheritance/4// which is based on implementations by Prototype / base256;(function(){7 var global = this, initialize = true8 var referencesSuper = /xyz/.test(function(){ xyz }) ? /\b__super__\b/ : /.*/910 /**11 * Shortcut for Class.extend()12 *13 * @param {hash} props14 * @return {function}15 * @api public16 */1718 Class = function(props){19 if (this == global)20 return Class.extend(props) 21 }22 23 // --- Version24

Updated js-oo to 1.1.0 for mixins etcvisionmediabefore adoption37948d8

line 25why, one step back
25 Class.version = '1.1.0'

Added Collection#reject()visionmediabefore adoptiondd76816

lines 26–63why, one step back
26
27 /**28 * Create a new class.29 *30 * User = Class({31 * init: function(name){32 * this.name = name33 * }34 * })35 *36 * Classes may be subclassed using the .extend() method, and37 * the associated superclass method via this.__super__().38 *39 * Admin = User.extend({40 * init: function(name, password) {41 * this.__super__(name)42 * // or this.__super__.apply(this, arguments)43 * this.password = password44 * }45 * })46 *47 * @param {hash} props48 * @return {function}49 * @api public50 */51 52 Class.extend = function(props) {53 var __super__ = this.prototype54 55 initialize = false56 var prototype = new this57 initialize = true5859 function Class() {60 if (initialize && this.init)61 this.init.apply(this, arguments)62 }63

Updated js-oo to 1.1.0 for mixins etcvisionmediabefore adoption37948d8

lines 64–86why, one step back
64 Class.include = function(props) {
65 for (var name in props)66 if (name == 'include')67 if (props[name] instanceof Array)68 for (var i = 0, len = props[name].length; i < len; ++i)69 Class.include(props[name][i])70 else71 Class.include(props[name])72 else if (props.hasOwnProperty(name))73 prototype[name] = 74 typeof props[name] == 'function' &&75 typeof __super__[name] == 'function' &&76 referencesSuper.test(props[name]) ?77 (function(name, fn){78 return function() {79 this.__super__ = __super__[name]80 return fn.apply(this, arguments)81 }82 })(name, props[name])83 : props[name]84 }85 86 Class.include(props)

Added Collection#reject()visionmediabefore adoptiondd76816

lines 87–93why, one step back
87 Class.prototype = prototype
88 Class.constructor = Class89 Class.extend = arguments.callee90 91 return Class92 }93})()