Created
June 8, 2017 09:35
-
-
Save fillano/4a3f9a744cb8f8edd0028fd1b976f5b2 to your computer and use it in GitHub Desktop.
create class with readonly attribute.
This file contains hidden or 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
const t = Symbol('ttt'); | |
module.exports = class { | |
constructor(name) { | |
this[t] = name; | |
} | |
get name() { | |
return this[t]; | |
} | |
sayHello() { | |
console.log(`Hello ${this.name}`); | |
} | |
} |
This file contains hidden or 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
const Greeting = require('./mod1'); | |
let m1 = new Greeting('Fillano'); | |
m1.sayHello();//show 'Hello Fillano' | |
console.log(m1.name);//show 'Fillano' | |
m1.name = 'Allen'; | |
console.log(m1.name);//still show 'Fillano' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment