Last active
August 29, 2015 14:06
-
-
Save ada-lovecraft/cf5b9411064a5b09eb74 to your computer and use it in GitHub Desktop.
the grossest thing i've written in a long time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Adds aliases to any Object so that they can be used more semantically in code | |
* | |
* @method Phaser.Utils#propertyAlias | |
* @param {propetyName} obj - The object to add an alias to | |
* @param {string} [propertyName] - the current property name to alias | |
* @param {string} [aliasName] - the alias | |
* @static | |
* @example | |
* Phaser.Utils.propertyAlias(Phaser.Point.prototype, 'x', 'width'); | |
* Phaser.Utils.propertyAlias(Phaser.Point.prototype, 'y', 'height'); | |
* var dimensions = new Phaser.Point(10,20); | |
* console.log(dimensions.width, dimensions.height); // 10 20; | |
*/ | |
Phaser.Utils.propertyAlias = function(obj, propertyName, aliasName) { | |
if(obj[aliasName]) { | |
throw new Error('object already has a property named', aliasName); | |
} else { | |
Object.defineProperty(obj, aliasName, { | |
get: function() { | |
return this[propertyName]; | |
}, | |
set: function(val) { | |
this[propertyName] = val; | |
} | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment