// es5类
function Dog(name,age){
this.name = name;
this.age = age;
}
Dog.prototype.bark = function(){
console.log('我是'+this.name);
}
let lili = new Dog('lili',1);
const wancai = new Dog('wancai',3);
console.log(lili);
console.log(wancai);
for(var i in lili){
console.log(i);
}
// var a = new Dog.bark();
// console.log(a);不能使用new调用类的方法
// es6类
class Person {
constructor(name,age){//必须用constructor(){}这种形式
this.name = name;
this.age = age;
}//不要用逗号, 这不是对象
talk(){
console.log('hello,我是' + this.name);
}
}
let xiaoming = new Person('xiaoming',18);
console.log(typeof Person);//function
for(var i in xiaoming){
console.log(i);//不能遍历方法
}