UNPKG

1.01 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2015-present, Facebook, Inc.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * strict
8 */
9
10/**
11 * The `applyToStringTag()` function checks first to see if the runtime
12 * supports the `Symbol` class and then if the `Symbol.toStringTag` constant
13 * is defined as a `Symbol` instance. If both conditions are met, the
14 * Symbol.toStringTag property is defined as a getter that returns the
15 * supplied class constructor's name.
16 *
17 * @method applyToStringTag
18 *
19 * @param {Class<any>} classObject a class such as Object, String, Number but
20 * typically one of your own creation through the class keyword; `class A {}`,
21 * for example.
22 */
23export default function applyToStringTag(classObject) {
24 if (typeof Symbol === 'function' && Symbol.toStringTag) {
25 Object.defineProperty(classObject.prototype, Symbol.toStringTag, {
26 get: function get() {
27 return this.constructor.name;
28 }
29 });
30 }
31}
\No newline at end of file