Skip to content

Instantly share code, notes, and snippets.

@solominh
Created January 21, 2017 23:28
Show Gist options
  • Save solominh/b289630749d54470e5ca9cd1d329ded7 to your computer and use it in GitHub Desktop.
Save solominh/b289630749d54470e5ca9cd1d329ded7 to your computer and use it in GitHub Desktop.
class Person {
constructor(name) {
this.name = name;
}
static realStaticMethod() {
console.log('static method');
}
}
var john = new Person('john');
// Real static method
john.realStaticMethod() // Error => static cannot be accessed by instance
Person.realStaticMethod() // static method
Person.prototype.realStaticMethod() // undefined => run Error
john.__proto__.constructor.realStaticMethod() // static method
// Real static property
Person.realStaticProperty = 10;
john.realStaticProperty // undefined
john.__proto__.constructor.realStaticProperty // 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment