var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
是这样调用的 __extends(Fish, _super);
这是一个继承方法,但是有一处地方看不懂 (this && this.__extends) 这个处理是什么意思?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
如果
this已定义且存在this.__extends, 则使用this.__extends, 否则等于一个自定义的函数function (d, b) {}, 相当于如果有 __extends,就直接使用原有的__extends,如果没有就才创建
放止重复添加 __extends 如果已经有了就不再重新extends
this && this.__extends因为在javascript中访问undefined的属性是会报错的,这里就是为了访问this.__extends不报错,因为如果this为undefined的话&&操作符就直接返回false。在这里就是确保当访问__extends时候,this是有值的(当然不是undefined之类的)现在我们把
this && this.__extends看作为一个整体a,那么由于操作符的优先级设定,实际上是__extends = a || function() {...}这就保证当a返回false的时候__extends默认取得后面的函数作为他的值。(this && this.__extends)说的在通俗点就是,当this有值并且已经有方法this.__extends就返回这个方法,否则返回后面一个函数。保证变量__extends现在指向的就是我们想要的那个函数。