| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Function/apply | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..
:
call(), , call() , apply() .
fun.apply(thisArg, [argsArray])
this . this , . apply() , .
apply call(), . . apply , , fun.apply(this, ['', '']), Array, , fun.apply(this, new Array('', '')).
argsArray arguments. arguments . . , , apply(). arguments . .
5- ECMAScript, , , length (0...length). , NodeList { 'length': 2, '0': '', '1': '' }.
: , Chrome 14 Internet Explorer 9, .
apply() apply() , Java. Function construct(), .
Function.prototype.construct = function (aArgs) {
var oNew = Object.create(this.prototype);
this.apply(oNew, aArgs);
return oNew;
};
:
Object.create(), , . :
Function.prototype.construct = function (aArgs) {
var fConstructor = this,
fNewConstr = function () {
fConstructor.apply(this, aArgs);
};
fNewConstr.prototype = fConstructor.prototype;
return new fNewConstr();
};
:
function MyConstructor() {
for (var nProp = 0; nProp < arguments.length; nProp++) {
this["property" + nProp] = arguments[nProp];
}
}
var myArray = [4, ", !", false];
var myInstance = MyConstructor.construct(myArray);
alert(myInstance.property1); // ', !'
alert(myInstance instanceof MyConstructor); // 'true'
alert(myInstance.constructor); // 'MyConstructor'
:
Function.construct() ( Date, ). Function.prototype.bind() (, , , Date: [2012, 11, 4]; - : new (Function.prototype.bind.apply(Date, [null].concat([2012, 11, 4])))() , , , ).
apply() apply() , . Math.max()/Math.min() / .
/* / */
var numbers = [5, 6, 2, 3, 7];
/* apply Math.min/Math.max */
var max = Math.max.apply(
null,
numbers,
); /* Math.max(numbers[0], ...)
Math.max(5, 6, ...) */
var min = Math.min.apply(null, numbers);
/* */
((max = -Infinity), (min = +Infinity));
for (var i = 0; i < numbers.length; i++) {
if (numbers[i] > max) {
max = numbers[i];
}
if (numbers[i] < min) {
min = numbers[i];
}
}
: apply() JavaScript. (, ) (JavaScriptCore 65536), ( , ) . . , . ( : [ , , ], , apply() 5, 6, 2, 3, .) , : :
function minOfArray(arr) {
var min = Infinity;
var QUANTUM = 32768;
for (var i = 0, len = arr.length; i < len; i += QUANTUM) {
var submin = Math.min.apply(null, arr.slice(i, Math.min(i + QUANTUM, len)));
min = Math.min(submin, min);
}
return min;
}
var min = minOfArray([5, 6, 2, 3, 7]);
apply() monkey- apply() monkey- Firefox , JS . someobject.foo(), :
var originalfoo = someobject.foo;
someobject.foo = function () {
// -
console.log(arguments);
// , :
originalfoo.apply(this, arguments);
// - .
};
, , -, API, .on([event]..., , ).
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-function.prototype.apply |
This page was last modified on 29 . 2026 . by MDN contributors.
FunctionObject/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |