Family of Nicky and Cookie
'use strict'
class Task{
}
console.log(typeof Task);//function
'use strict'
class Task{
}
let task = new Task();
console.log(typeof task);//object
console.log(task instanceof Task);//true
'use strict'
class Task{
showId(){
console.log('99');
}
}
let task = new Task();
console.log(task.showId===Task.prototype.showId);//true
'use strict'
class Task{
constructor(){
console.log('constructing Task');
}//没有逗号
showId(){
console.log('99');
}
}
let task = new Task();//'constructing Task'
'use strict'
class Task{
let taskId=9000;
constructor(){
console.log('constructing Task');
}//没有逗号
showId(){
console.log('99');
}
}
let task = new Task();//'constructing Task'
let Task = function(){
console.log('constructing Task');
};
let task = {};
Task.call(task);
//------------------------------------------
class Task{
constructor(){
console.log('constructing Task');
}
};
let task = {};
Task.call(task);//syntax error
function Project(){}
console.log(window.Project === Project);//true
//------------------------------------------------
class Task{}
console.log(window.Task === Task);//false,namespace不同
class Project{
constructor(){
console.log('constructing Project');
}
}
class SoftwareProject extends Project{
}
let p = new SoftwareProject();//'constructing Project'
class Project{
constructor(name){
console.log('constructing Project '+ name);
}
}
class SoftwareProject extends Project{
}
let p = new SoftwareProject('Mazatlan');//'constructing Project Mazatlan'
class Project{
constructor(){
console.log('constructing Project');
}
}
class SoftwareProject extends Project{
super();
console.log('constructing Software');
}
let p = new SoftwareProject('Mazatlan');
//'constructing Project'
//'constructing Software'
class Project{
getTaskCount(){
return 50;
}
}
class SoftwareProject extends Project{
getTaskCount(){
return 66;
//also can return super.getTaskCount()+5;
}
}
let p = new SoftwareProject('Mazatlan');
p.getTaskCount();//66
let project = {
getTaskCount(){return 50;}
};
let softwareProject = {
getTaskCount(){
return super.getTaskCount()+7;
}
};
Object.setPrototypeOf(softwareProject,project);
console.log(softwareProject.getTaskCount());//57
class Project{
constructor(){this.location='Mazation'}
}
class SoftwareProject extends Project{
constructor(){
super();
this.location = this.location + 'Beach'
}
}
let p = new SoftwareProject();
console.log(p.location);//'Mazation Beach'
class Project{
static getDefaultId(){
return 0;
}
}
console.log(Project.getDefaultId());//0
class Project{
static getDefaultId(){
return 0;
}
}
let p = new Project()
console.log(p.getDefaultId());//syntax error
class Project{
static let id=0;
}
console.log(Project.id);//syntax error
class Project{
}
Project.id = 99;
console.log(Project.id);//99
class Project{
constructor(){
console.log(typeof new.target);
console.log(new.target);
}
}
var p= new Project();