mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
320f433dcd
Classes cannot be instantiated without new, but util.deprecate() uses Function.prototype.apply(). This commit uses new.target to detect constructor calls, allowing classes to be deprecated. PR-URL: https://github.com/nodejs/node/pull/7690 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
20 lines
410 B
JavaScript
20 lines
410 B
JavaScript
const util = require('util');
|
|
const assert = require('assert');
|
|
|
|
class deprecatedClass {
|
|
}
|
|
|
|
const deprecated = util.deprecate(deprecatedClass, 'deprecatedClass is deprecated.');
|
|
|
|
class subclass extends deprecated {
|
|
constructor() {
|
|
super();
|
|
}
|
|
}
|
|
|
|
const instance = new subclass();
|
|
|
|
assert(instance instanceof subclass);
|
|
assert(instance instanceof deprecated);
|
|
assert(instance instanceof deprecatedClass);
|