Created
January 26, 2013 07:31
-
-
Save leoj3n/4640804 to your computer and use it in GitHub Desktop.
Playing around with EcmaScript 6 using the Traceur compiler. Digging it!
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
// Live demo: http://traceur-compiler.googlecode.com/git/demo/repl.html#module%20Player%20{%0A%20%20let%20options%20%3D%20new%20WeakMap%28%29%3B%0A%20%20%0A%20%20export%20class%20Controller%20{%0A%20%20%20%20constructor%28%20id%20%3D%200%2C%20type%20%3D%20%22jwplayer%22%20%29%20{%0A%20%20%20%20%20%20options.set%28%20this%2C%20{%20id%3A%20id%2C%20type%3A%20type%20}%20%29%3B%0A%20%20%20%20}%0A%20%20%20%20name%28%29%20{%0A%20%20%20%20%20%20return%20%22contoller%22%20%2B%20options.get%28this%29[%22id%22]%3B%0A%20%20%20%20}%0A%20%20%20%20setId%28%20id%20%3D%200%20%29%20{%0A%20%20%20%20%20%20options.get%28this%29[%22id%22]%20%3D%20id%3B%0A%20%20%20%20}%0A%20%20}%0A}%0A%0Aimport%20{%20Controller%20}%20from%20Player%3B%0A%0Avar%20c%20%3D%20new%20Controller%28%201%20%29%3B%0A%0Ac.setId%28%20300%20%29%3B%0A%0Aconsole.log%28%20%22Controller%20name%3A%20%22%20%2B%20c.name%28%29%20%29%3B | |
module Player { | |
let options = new WeakMap(); | |
export class Controller { | |
constructor( id = 0, type = "jwplayer" ) { | |
options.set( this, { id: id, type: type } ); | |
} | |
name() { | |
return "contoller" + options.get(this)["id"]; | |
} | |
setId( id = 0 ) { | |
options.get(this)["id"] = id; | |
} | |
} | |
} | |
import { Controller } from Player; | |
var c = new Controller( 1 ); | |
c.setId( 300 ); | |
console.log( "Controller name: " + c.name() ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment