211
Ze
zen / files
2.3 KB
1 2// usage: log('inside coolFunc', this, arguments); 3// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/ 4window.log = function(){ 5 log.history = log.history || []; // store logs to an array for reference 6 log.history.push(arguments); 7 if(this.console) console.log( Array.prototype.slice.call(arguments) ); 8}; 9 10/* Simple JavaScript Inheritance 11 * By John Resig http://ejohn.org/ 12 * MIT Licensed. 13 */ 14 15// Inspired by base2 and Prototype 16(function(){ 17 var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; 18 // The base Class implementation (does nothing) 19 this.Class = function(){}; 20 21 // Create a new Class that inherits from this class 22 Class.extend = function(prop) { 23 var _super = this.prototype; 24 25 // Instantiate a base class (but only create the instance, 26 // don't run the init constructor) 27 initializing = true; 28 var prototype = new this(); 29 initializing = false; 30 31 // Copy the properties over onto the new prototype 32 for (var name in prop) { 33 // Check if we're overwriting an existing function 34 prototype[name] = typeof prop[name] == "function" && 35 typeof _super[name] == "function" && fnTest.test(prop[name]) ? 36 (function(name, fn){ 37 return function() { 38 var tmp = this._super; 39 40 // Add a new ._super() method that is the same method 41 // but on the super-class 42 this._super = _super[name]; 43 44 // The method only need to be bound temporarily, so we 45 // remove it when we're done executing 46 var ret = fn.apply(this, arguments); 47 this._super = tmp; 48 49 return ret; 50 }; 51 })(name, prop[name]) : 52 prop[name]; 53 } 54 55 // The dummy class constructor 56 function Class() { 57 // All construction is actually done in the init method 58 if ( !initializing && this.init ) 59 this.init.apply(this, arguments); 60 } 61 62 // Populate our constructed prototype object 63 Class.prototype = prototype; 64 65 // Enforce the constructor to be what we expect 66 Class.constructor = Class; 67 68 // And make this class extendable 69 Class.extend = arguments.callee; 70 71 return Class; 72 }; 73})(); 74 75// place any jQuery/helper plugins in here, instead of separate, slower script files. 76