diff --git a/src/core/Base.js b/src/core/Base.js index 65615afd..0f5968ad 100644 --- a/src/core/Base.js +++ b/src/core/Base.js @@ -14,14 +14,17 @@ * All rights reserved. */ -// Extend Base with utility functions used across the library. Also set -// this.Base on the injection scope, since bootstrap.js ommits that. /** * @name Base * @class * @private */ +// Extend Base with utility functions used across the library. Also set +// this.Base on the injection scope, since bootstrap.js ommits that. this.Base = Base.inject(/** @lends Base# */{ + // Have generics versions of #clone() and #toString(): + generics: true, + /** * General purpose clone function that delegates cloning to the constructor * that receives the object to be cloned as the first argument. @@ -32,6 +35,16 @@ this.Base = Base.inject(/** @lends Base# */{ return new this.constructor(this); }, + /** + * Renders base objects to strings in object literal notation. + */ + toString: function() { + return '{ ' + Base.each(this, function(value, key) { + this.push(key + ': ' + (typeof value === 'number' + ? Base.formatNumber(value) : value)); + }, []).join(', ') + ' }'; + }, + statics: /** @lends Base */{ /** * Reads arguments of the type of the class on which it is called on @@ -102,12 +115,15 @@ this.Base = Base.inject(/** @lends Base# */{ } }, + /** + * Merge all passed hash objects into a newly creted Base object. + */ merge: function() { return Base.each(arguments, function(hash) { Base.each(hash, function(value, key) { this[key] = value; }, this); - }, {}, true); // Pass true for asArray. + }, new Base(), true); // Pass true for asArray, as arguments is none }, /** @@ -142,16 +158,6 @@ this.Base = Base.inject(/** @lends Base# */{ */ formatNumber: function(num) { return (Math.round(num * 100000) / 100000).toString(); - }, - - /** - * Utility function for rendering objects to strings, in object literal - * notation. - */ - formatObject: function(obj) { - return '{ ' + Base.each(obj, function(value, key) { - this.push(key + ': ' + value); - }, []).join(', ') + ' }'; } } }); diff --git a/src/ui/Key.js b/src/ui/Key.js index 725f020e..76f9a203 100644 --- a/src/ui/Key.js +++ b/src/ui/Key.js @@ -43,17 +43,14 @@ var Key = this.Key = new function() { 91: 'command' }, - modifiers = { + // Use Base.merge to convert into a Base object, for #toString() + modifiers = Base.merge({ shift: false, control: false, option: false, command: false, - capsLock: false, - - toString: function() { - return Base.formatObject(this); - } - }, + capsLock: false + }), // Since only keypress gets proper keyCodes that are actually representing // characters, we need to perform a little trickery here to use these codes diff --git a/src/ui/View.js b/src/ui/View.js index dd7b9165..9bf57654 100644 --- a/src/ui/View.js +++ b/src/ui/View.js @@ -357,11 +357,12 @@ var View = this.View = Base.extend(/** @lends View# */{ } var now = Date.now() / 1000, delta = before ? now - before : 0; - that._onFrame({ + // Use Base.merge to convert into a Base object, for #toString() + that._onFrame(Base.merge({ delta: delta, // Time elapsed since last redraw in seconds time: time += delta, // Time since first call of frame() in seconds count: count++ - }); + })); before = now; // Automatically draw view on each frame. that.draw(true);