// 方式一:之前创建一个类
// function Animal(name){
// this.name = name;
// }
// Animal.prototype.showName = function(){
// console.log(this.name);
// }
// var tom = new Animal("Tom");
// var jerry = new Animal("Jerry");
// tom.showName();
// jerry.showName();
// -----------------------------
// 方式二:创建类(class + 构造函数)
// class Animal{
// // 构造函数
// constructor(name){
// this.name = name;
// }
// showName(){
// console.log(this.name)
// }
// }
// let a = new Animal("Spider")
// a.showName()
// ------------------------------------
// 类的静态方法(只能通过类名来调用,不可以使用实例对象来调用)
// class Animal{
// static greet(){
// console.log("hello!")
// };
// constructor(name,age){
// this.name = name;
// this.age = age;
// };
// showInfo(){
// console.log(this.name);
// console.log(this.age);
// }
// }
// Animal.greet()
// var
Nodejs类与继承
最新推荐文章于 2024-05-09 09:32:56 发布