1 Star 0 Fork 0

EastM/learn-typescript

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
class.js 1.99 KB
一键复制 编辑 原始数据 按行查看 历史
EastM 提交于 2020-06-19 11:04 . 基本巩固完毕
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();
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/EastM/learn-typescript.git
git@gitee.com:EastM/learn-typescript.git
EastM
learn-typescript
learn-typescript
master

搜索帮助