為了使用 nodejs 6.10.1 升級指令:
1. curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
2. sudo apt-get install -y nodejs
// javascript 程式使用 class
class ClassA {
constructor(name) {
this.aliasName = name;
}
get name() {
return this.aliasName.toUpperCase();
}
set name(name){
if(name){
this.aliasName = name;
}
}
}
class ClassB extends ClassA {
constructor(name) {
super(name);// super needs to be called first
this.newp = function(){console.log("Hi"); }
}
}
let a = new ClassB("first"); // invoke constructor
console.log(a.aliasName+' : '+a.name); // invoke getter
a.name = "second"; // invoke setter
console.log(a.aliasName+' : '+a.name);// invoke getter
a.newp();
沒有留言:
張貼留言