Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
newのように演算子がオプションになるように、jQuery はその Deferred オブジェクトをどのように実装しvar x = $.Deferred();ますか?
new
var x = $.Deferred();
これがそれを達成するためのパターンです...
$.Deferred = function() { if ( ! (this instanceof $.Deferred)) { return new $.Deferred; } }
thisコンストラクターで新しいオブジェクトに設定されているため、機能します。instanceofLHS オペランドのプロトタイプ チェーンに RHS オペランドがあるかどうかがわかります。この条件が真でない場合、関数はオブジェクトのインスタンス化されたバージョンを返します。
this
instanceof