main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
744 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var define = require('define-data-property');
|
---|
4 | var hasDescriptors = require('has-property-descriptors')();
|
---|
5 | var functionsHaveConfigurableNames = require('functions-have-names').functionsHaveConfigurableNames();
|
---|
6 |
|
---|
7 | var $TypeError = require('es-errors/type');
|
---|
8 |
|
---|
9 | /** @type {import('.')} */
|
---|
10 | module.exports = function setFunctionName(fn, name) {
|
---|
11 | if (typeof fn !== 'function') {
|
---|
12 | throw new $TypeError('`fn` is not a function');
|
---|
13 | }
|
---|
14 | var loose = arguments.length > 2 && !!arguments[2];
|
---|
15 | if (!loose || functionsHaveConfigurableNames) {
|
---|
16 | if (hasDescriptors) {
|
---|
17 | define(/** @type {Parameters<define>[0]} */ (fn), 'name', name, true, true);
|
---|
18 | } else {
|
---|
19 | define(/** @type {Parameters<define>[0]} */ (fn), 'name', name);
|
---|
20 | }
|
---|
21 | }
|
---|
22 | return fn;
|
---|
23 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.