Created
December 7, 2012 21:39
-
-
Save davepeck/4236746 to your computer and use it in GitHub Desktop.
ES5 properties and coffee script
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
Function::property = (prop, desc) -> | |
Object.defineProperty this.prototype, prop, desc | |
class Foo | |
@property 'neat' | |
get: -> | |
42 | |
class Bar extends Foo | |
@property 'neat' | |
get: -> | |
super | |
# 42 | |
alert(new Foo().neat) | |
# exception | |
alert(new Bar().neat) |
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
Function::property = (prop, desc) -> | |
Object.defineProperty this.prototype, prop, desc | |
class Foo | |
@property 'neat' | |
get: -> | |
42 | |
class Bar extends Foo | |
@property 'neat' | |
get: -> | |
Bar.__super__.neat | |
# 42 | |
alert(new Foo().neat) | |
# 42 | |
alert(new Bar().neat) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi all and thx for the example(s),
@ben-x9:
It works with setters when one changes the getter-definition
to allow a following setter-definition. The code as-is throws 'Cannot redefine property ' in Chrome.
cheers, Andreas