How to use functions-have-names - 3 common examples

To help you get started, we’ve selected a few functions-have-names examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github es-shims / String.prototype.matchAll / test / shimmed.js View on Github external
'use strict';

require('es5-shim');
require('es6-shim');
var matchAllShim = require('../');
matchAllShim.shim();

var test = require('tape');
var defineProperties = require('define-properties');
var bind = require('function-bind');
var hasSymbols = require('has-symbols')();
var regexMatchAll = require('../regexp-matchall');

var isEnumerable = Object.prototype.propertyIsEnumerable;
var functionsHaveNames = require('functions-have-names')();
var functionNamesConfigurable = require('functions-have-names').functionsHaveConfigurableNames();

var runTests = require('./tests');

test('shimmed', function (t) {
	t.equal(String.prototype.matchAll.length, 1, 'String#matchAll has a length of 1');
	t.test('Function name', { skip: !functionsHaveNames }, function (st) {
		st.equal(String.prototype.matchAll.name, 'matchAll', 'String#matchAll has name "matchAll"');
		st.end();
	});

	t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
		et.equal(false, isEnumerable.call(String.prototype, 'matchAll'), 'String#matchAll is not enumerable');
		et.end();
	});

	t.test('Symbol.matchAll', { skip: !hasSymbols }, function (st) {
github es-shims / AggregateError / test / tests.js View on Github external
'use strict';

var functionsHaveNames = require('functions-have-names')();
var boundFunctionsHaveNames = require('functions-have-names').boundFunctionsHaveNames();
var forEach = require('for-each');
var inspect = require('object-inspect');

module.exports = function (AggregateError, t) {
	t.test('constructor', function (st) {
		st.equal(typeof AggregateError, 'function', 'is a function');

		st.equal(AggregateError.length, 2, 'AggregateError has a length of 2');

		st.test('Function name', { skip: !functionsHaveNames || !boundFunctionsHaveNames }, function (s2t) {
			s2t.equal(AggregateError.name, 'AggregateError', 'AggregateError has name "AggregateError"');
			s2t.end();
		});

		st.end();
	});
github es-shims / AggregateError / index.js View on Github external
'use strict';

var bind = require('function-bind');
var define = require('define-properties');
var functionsHaveConfigurableNames = require('functions-have-names').functionsHaveConfigurableNames();

var implementation = require('./implementation');
var getPolyfill = require('./polyfill');
var shim = require('./shim');

var polyfill = getPolyfill();
var bound = bind.call(polyfill);
if (functionsHaveConfigurableNames) {
	Object.defineProperty(bound, 'name', { value: polyfill.name });
}
bound.prototype = polyfill.prototype;

define(bound, {
	getPolyfill: getPolyfill,
	implementation: implementation,
	shim: shim

functions-have-names

Does this JS environment support the `name` property on functions?

MIT
Latest version published 2 years ago

Package Health Score

67 / 100
Full package analysis