76 lines
2.4 KiB
JavaScript
76 lines
2.4 KiB
JavaScript
/**
|
|
* Copyright (c) 2012, Andy Janata
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without modification, are permitted
|
|
* provided that the following conditions are met:
|
|
*
|
|
* * Redistributions of source code must retain the above copyright notice, this list of conditions
|
|
* and the following disclaimer.
|
|
* * Redistributions in binary form must reproduce the above copyright notice, this list of
|
|
* conditions and the following disclaimer in the documentation and/or other materials provided
|
|
* with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
|
|
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
var cah = {};
|
|
|
|
/**
|
|
* This client's nickname.
|
|
*
|
|
* @type {string}
|
|
*/
|
|
cah.nickname = "";
|
|
|
|
/**
|
|
* The games this client is playing in. Key is game id.
|
|
*
|
|
* @type {Object}
|
|
*/
|
|
cah.currentGames = {};
|
|
|
|
/**
|
|
* Binds a function to a "this object". Result is a new function that will do the right thing across
|
|
* contexts.
|
|
*
|
|
* @param {Object}
|
|
* selfObj Object for "this" when calling the returned function.
|
|
* @param {Function}
|
|
* func Function to call with selfObjc as "this".
|
|
* @returns {Function}
|
|
*/
|
|
cah.bind = function(selfObj, func) {
|
|
return function() {
|
|
func.apply(selfObj, arguments);
|
|
};
|
|
};
|
|
|
|
/**
|
|
* Inherit the proto methods from one constructor to another.
|
|
*
|
|
* @param {Function}
|
|
* childCtor Child class.
|
|
* @param {Function}
|
|
* parentCtor Parent class.
|
|
*/
|
|
cah.inherits = function(childCtor, parentCtor) {
|
|
/** @constructor */
|
|
function tempCtor() {
|
|
// pass
|
|
}
|
|
;
|
|
|
|
tempCtor.prototype = parentCtor.prototype;
|
|
childCtor.superClass_ = parentCtor.prototype;
|
|
childCtor.prototype = new tempCtor();
|
|
childCtor.prototype.constructor = childCtor;
|
|
};
|