Skip to content

Instantly share code, notes, and snippets.

@leoj3n
Created January 26, 2013 07:31
Show Gist options
  • Save leoj3n/4640804 to your computer and use it in GitHub Desktop.
Save leoj3n/4640804 to your computer and use it in GitHub Desktop.
Playing around with EcmaScript 6 using the Traceur compiler. Digging it!
// 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