-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbase.js
34 lines (32 loc) · 979 Bytes
/
base.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* @fileoverview This file contains some base functions useful to both the
* server and the client.
* @author [email protected] (Alvin Lin)
*/
/**
* This extension of the Function class allows for class inheritance.
* Example usage:
* require('./inheritable');
* Player.inheritsFrom(Entity);
* @param {Function} parent The child object which should inherit from this
* object.
* @return {Function}
*/
Function.prototype.inheritsFrom = function(parent) {
this.prototype = new parent();
this.prototype.constructor = this;
this.prototype.parent = parent.prototype;
return this;
};
/**
* Binds a function to a context, useful for assigning event handlers and
* function callbacks.
* @param {Object} context The context to assign the method to.
* @param {function(?)} method The method to bind the context to.
* @return {function(?)}
*/
function bind(context, method) {
return function() {
return method.apply(context, arguments);
};
}