代码拉取完成,页面将自动刷新
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var Animal = /** @class */ (function () {
function Animal(name) {
this.name = name;
}
Animal.isAnimal = function (instace) {
return instace instanceof Animal;
};
Animal.prototype.run = function () {
return 'running';
};
//静态属性
Animal.age = 2; //和java 一样都只能被类本身调用;不能被实例调用
return Animal;
}());
var snake = new Animal('lucy');
var isnimale = Animal.isAnimal(snake);
console.log(isnimale);
snake.name = 'lili';
var Dog = /** @class */ (function (_super) {
__extends(Dog, _super);
function Dog() {
return _super !== null && _super.apply(this, arguments) || this;
}
Dog.prototype.bark = function () {
return this.name + " is barking";
};
return Dog;
}(Animal));
var Cat = /** @class */ (function (_super) {
__extends(Cat, _super);
function Cat(name) {
var _this = _super.call(this, name) || this;
_this.miao = function () {
console.log(this.name + "\u55B5");
};
return _this;
}
//重写run 方法
Cat.prototype.run = function () {
console.log('喵' + ("" + this.name) + _super.prototype.run.call(this));
return '喵' + ("" + this.name) + _super.prototype.run.call(this);
};
return Cat;
}(Animal));
var dog = new Dog('狗');
var cat = new Cat('小花');
console.log(dog.bark());
console.log(dog.run());
cat.miao();
cat.run();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。