Here is a template to achieve this ...
$.Deferred = function() {
if ( ! (this instanceof $.Deferred)) {
return new $.Deferred;
}
}
This works because the thisconstructor is set to a new object. instanceofwill tell you if the LHS operand has an RHS operand in its prototype chain. If this condition is not true, the function will return an instance version of the object.
source
share