Skip to content

Instantly share code, notes, and snippets.

@tyage
Last active August 29, 2015 14:10
Show Gist options
  • Save tyage/2752308e92aff4785ab8 to your computer and use it in GitHub Desktop.
Save tyage/2752308e92aff4785ab8 to your computer and use it in GitHub Desktop.
"use strict"
class C {
constructor() {
this.x = 1
}
say(str) {
console.log(str)
}
static static() {
console.log(this)
}
}
console.log(C.prototype) // => { say: [Function] }
console.log(C.prototype.constructor === C) // => true
let a = new C
a.say('hi') // => hi
C.prototype.say = () => console.log('wow')
a.say('hi') // => wow
class D extends C {
sup() {
console.log(super.constructor === C) // => true
super.say('yoyoyo') // => wow
}
}
console.log(D.prototype.constructor === D) // => true
console.log(D.prototype.say == C.prototype.say) // => true
console.log(C.isPrototypeOf(D)) // => true
let b = new D
b.sup()
class E extends function() {
console.log('test')
} {
get a() {
return 1
}
*generator () {
yield 2
}
static set b(param) {
console.log('set b to ' + param)
}
}
a = new E // => test
console.log(a.a) // => 1
console.log(a.generator().next().value) // => 2
console.log(E.name) // => E
E.b = 1 // => set b to 1
try {
class F {
static name() { }
}
} catch (e) {
console.log(e) // => [TypeError: Cannot redefine property: name]
}
class G extends Array {
constructor() {
return super(1, 2)
// new super() // => error in traceur
}
}
console.log(new G) // => [ 1, 2 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment