| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Function/call | [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 7.
call() this .
:
apply() , call() , apply() .
function Product(name, price) {
this.name = name;
this.price = price;
}
function Food(name, price) {
Product.call(this, name, price);
this.category = "food";
}
console.log(new Food("cheese", 5).name);
// Expected output: "cheese"
func.call(thisArg[, arg1[, arg2[, ...]]])
thisArgfunc this .
this arguments
call() / . this ( ) . call() .
call Java , (chain) call . , Product name price . Food Toy this name price Product . Product name price , (Food Toy) category .
function Product(name, price) {
this.name = name;
this.price = price;
if (price < 0) {
throw RangeError(
"Cannot create product " + this.name + " with a negative price",
);
}
}
function Food(name, price) {
Product.call(this, name, price);
this.category = "food";
}
function Toy(name, price) {
Product.call(this, name, price);
this.category = "toy";
}
var cheese = new Food("feta", 5);
var fun = new Toy("robot", 40);
call call . print .
:
this , .
var animals = [
{ species: "Lion", name: "King" },
{ species: "Whale", name: "Fail" },
];
for (var i = 0; i < animals.length; i++) {
(function (i) {
this.print = function () {
console.log("#" + i + " " + this.species + ": " + this.name);
};
this.print();
}).call(animals[i], i);
}
this' call , greet this obj .
function greet() {
var reply = [this.animal, "typically sleep between", this.sleepDuration].join(
" ",
);
console.log(reply);
}
var obj = {
animal: "cats",
sleepDuration: "12 and 16 hours",
};
greet.call(obj); // cats typically sleep between 12 and 16 hours
call , display . , this .
var sData = "Wisen";
function display() {
console.log("sData value is %s ", this.sData);
}
display.call(); // sData value is Wisen
:
(strict mode), this undefined . See below.
"use strict";
var sData = "Wisen";
function display() {
console.log("sData value is %s ", this.sData);
}
display.call(); // Cannot read the property of 'sData' of undefined
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-function.prototype.call |
This page was last modified on 2026 7 15 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 |