This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.deprecate = function deprecate(fn, msg, code) { | |
// pre wrapper checks go here | |
function deprecated() { | |
if (!warned) { | |
warned = true; | |
if (code !== undefined) { | |
process.emitWarning(msg, 'DeprecationWarning', code, deprecated); | |
} else { | |
process.emitWarning(msg, 'DeprecationWarning', deprecated); | |
} | |
} | |
if (new.target) { | |
return Reflect.construct(fn, arguments, new.target); | |
} | |
return fn.apply(this, arguments); | |
} | |
// The wrapper will keep the same prototype as fn to maintain prototype chain | |
Object.setPrototypeOf(deprecated, fn); | |
if (fn.prototype) { | |
// Setting this (rather than using Object.setPrototype, as above) ensures | |
// that calling the unwrapped constructor gives an instanceof the wrapped | |
// constructor. | |
deprecated.prototype = fn.prototype; | |
} | |
return deprecated; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment