Skip to content

Commit

Permalink
Merge pull request #847 from arduino/dependabot/npm_and_yarn/eslint-p…
Browse files Browse the repository at this point in the history
…lugin-import-2.29.0

build(deps-dev): bump eslint-plugin-import from 2.28.1 to 2.29.0
  • Loading branch information
per1234 authored Oct 23, 2023
2 parents b17984c + d4c9518 commit 2676f14
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 153 deletions.
2 changes: 1 addition & 1 deletion .licenses/npm/function-bind.dep.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: function-bind
version: 1.1.1
version: 1.1.2
type: npm
summary: Implementation of Function.prototype.bind
homepage: https://github.com/Raynos/function-bind
Expand Down
56 changes: 44 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6512,43 +6512,75 @@ if ($defineProperty) {
/* eslint no-invalid-this: 1 */

var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
var slice = Array.prototype.slice;
var toStr = Object.prototype.toString;
var max = Math.max;
var funcType = '[object Function]';

var concatty = function concatty(a, b) {
var arr = [];

for (var i = 0; i < a.length; i += 1) {
arr[i] = a[i];
}
for (var j = 0; j < b.length; j += 1) {
arr[j + a.length] = b[j];
}

return arr;
};

var slicy = function slicy(arrLike, offset) {
var arr = [];
for (var i = offset || 0, j = 0; i < arrLike.length; i += 1, j += 1) {
arr[j] = arrLike[i];
}
return arr;
};

var joiny = function (arr, joiner) {
var str = '';
for (var i = 0; i < arr.length; i += 1) {
str += arr[i];
if (i + 1 < arr.length) {
str += joiner;
}
}
return str;
};

module.exports = function bind(that) {
var target = this;
if (typeof target !== 'function' || toStr.call(target) !== funcType) {
if (typeof target !== 'function' || toStr.apply(target) !== funcType) {
throw new TypeError(ERROR_MESSAGE + target);
}
var args = slice.call(arguments, 1);
var args = slicy(arguments, 1);

var bound;
var binder = function () {
if (this instanceof bound) {
var result = target.apply(
this,
args.concat(slice.call(arguments))
concatty(args, arguments)
);
if (Object(result) === result) {
return result;
}
return this;
} else {
return target.apply(
that,
args.concat(slice.call(arguments))
);
}
return target.apply(
that,
concatty(args, arguments)
);

};

var boundLength = Math.max(0, target.length - args.length);
var boundLength = max(0, target.length - args.length);
var boundArgs = [];
for (var i = 0; i < boundLength; i++) {
boundArgs.push('$' + i);
boundArgs[i] = '$' + i;
}

bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder);
bound = Function('binder', 'return function (' + joiny(boundArgs, ',') + '){ return binder.apply(this,arguments); }')(binder);

if (target.prototype) {
var Empty = function Empty() {};
Expand Down
Loading

0 comments on commit 2676f14

Please sign in to comment.