.ﺪﺷﺎﺑ ﻩﺩﺎﻔﺘﺳﺍ ﻞﺑﺎﻗ ﻒﻠﺘﺨﻣ ﺩﺭﺍﻮﻣ ﺭﺩ ﻪﮐ ﺪﯿﺴﯾﻮﻨﺑ ﯼﺪﺘﻣ ﺪﯿﻧﺍﻮﺗﯽﻣ ، .ﺖﺳﺍ (ﯽﻠﺒﻗ ﻞﺼﻓ) call() ﺵﻭﺭ ﻪﺑﺎﺸﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
apply() ﺵﻭﺭ
:ﺖﺳﺍ ﻩﺩﺎﻔﺘﺳﺍperson1 ﺭﺩ fullName per
const person = {
fullName: function() {
return this.firstName + " " + this.lastName;
}
}
const person1 = {
firstName: "Mary",
lastName: "Doe"
}
// This will return "Mary Doe":
person.fullName.apply(person1);→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p>In this example the fulllName method of person is <b>applied</b> on person1:</p>
<p id="demo"></p>
<script>
const person = {
fullName: function() {
return this.firstName + " " + this.lastName;
}
}
const person1 = {
firstName:"John",
lastName: "Doe"
}
document.getElementById("demo").innerHTML = person.fullName.apply(person1);
</script>
</body>
</html>
apply() ﻭ call() ﻦﯿﺑ ﺕﻭﺎﻔﺗ:ﺖﺳﺍ ﻦﯾﺍ ﺕﻭﺎﻔﺗ
.ﺩﺮﯿﮔ ﯽﻣ ﺍﺪﺟ ﺕﺭﻮﺻ ﻪﺑ ﺍﺭ ﺎﻫ ﻥﺎﻣﻮﮔﺭﺁ call()<
.ﺩﺮﯿﮔ ﯽﻣ ﻪﯾﺍﺭﺁ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﺎﻫ ﻥﺎﻣﻮﮔﺭﺁ appl
.ﺖﺳﺍ ﺪﯿﻔﻣ ﺭﺎﯿﺴﺑ()application ﺪﺘﻣ ،ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻪﯾﺍﺭﺁ ﺯﺍ ﻥﺎﻣﻮﮔﺭﺁ ﺖﺴﯿﻟ ﯼﺎﺟ ﻪﺑ ﺪﯿﻫﺍﻮﺨﺑ
apply() ﺵﻭﺭ :ﺩﺮﯾﺬﭘ ﯽﻣ ﻪﯾﺍﺭﺁ ﮏﯾ ﺭﺩ ﺍﺭ ﺎﻫ ﻥﺎﻣﻮﮔﺭﺁ apply() ﺵﻭﺭ
const person = {
fullName: function(city, country) {
return this.firstName + " " + this.lastName
+ "," + city + "," + country;
}
}
const person1 = {
firstName:"John",
lastName: "Doe"
}
person.fullName.apply(person1, ["Oslo", "Norway"]);→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p>In this example the fulllName method of person is <b>applied</b> on person1:</p>
<p id="demo"></p>
<script>
const person = {
fullName: function(city, country) {
return this.firstName + " " + this.lastName + "," + city + "," + country;
}
}
const person1 = {
firstName:"John",
lastName: "Doe"
}
document.getElementById("demo").innerHTML = person.fullName.apply(person1, ["Oslo", "Norway"]);
</script>
</body>
</html>
:call() ﺵﻭﺭ ﺎﺑ ﻪﺴﯾﺎﻘﻣ ﺭﺩ
const person = {
fullName: function(city, country) {
return this.firstName + " " + this.lastName
+ "," + city + "," + country;
}
}
const person1 = {
firstName:"John",
lastName: "Doe"
}
person.fullName.call(person1, "Oslo", "Norway");→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Functions</h2>
<p>This example calls the fullName method of person, using it on person1:
</p>
<p id="demo"></p>
<script>
const person = {
fullName: function(city, country) {
return this.firstName + " " + this.lastName + "," + city + "," + country;
}
}
const person1 = {
firstName:"John",
lastName: "Doe"
}
const person2 = {
firstName:"Mary",
lastName: "Doe"
}
document.getElementById("demo").innerHTML = person.fullName.call(person1, "Oslo", "Norway");
</script>
</body>
</html>
:ﺪﯿﺑﺎﯿﺑ (ﺩﺍﺪﻋﺍ ﺖﺴﯿﻟ ﺭﺩ) ﺍﺭ ﺩﺪﻋ ﻦﯾﺮﺘﮔﺭﺰﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ Math.max(
Math.max(1,2,3); // Will return 3→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Math.max()</h2>
<p>This example returns the highest number in a list of number arguments:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = Math.max(1,2,3);
</script>
</body>
</html>
ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ،ﺪﻧﺭﺍﺪﻧ()max ﺪﺘﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫﻪﯾﺍﺭﺁ ﻪﮐ ﯽﯾﺎﺠﻧﺁ ﺯﺍ
Math.max.apply(null, [1,2,3]); // Will also return 3→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript apply()</h2>
<p>This example returns the highest number in an array of numbers:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = Math.max.apply(null, [1,2,3]);
</script>
</body>
</html>
.ﺖﺳﺍ ﻩﺪﺸﻧ ﻩﺩﺎﻔﺘﺳﺍ ﻝﺎﺜﻣ ﻦﯾﺍ ﺭﺩ .ﺖﺴﯿﻧ ﻢﻬﻣ (null) ﻝﻭﺍ ﻥﺎﻣﻮﮔﺭﺁ
:ﺖﺷﺍﺩ ﺪﻨﻫﺍﻮﺧ ﺍﺭ ﻪﺠﯿﺘﻧ ﻥﺎﻤﻫ ﺎﻫﻝﺎﺜﻣ ﻦﯾﺍ
Math.max.apply(Math, [1,2,3]); // Will also return 3→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript apply()</h2>
<p>This example returns the highest number in an array of numbers:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = Math.max.apply(Math, [1,2,3]);
</script>
</body>
</html>
Math.max.apply(" ", [1,2,3]); // Will also return 3→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript apply()</h2>
<p>This example returns the highest number in an array of numbers:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = Math.max.apply(" ", [1,2,3]);
</script>
</body>
</html>
Math.max.apply(0, [1,2,3]); // Will also return 3→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript apply()</h2>
<p>This example returns the highest number in an array of numbers:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = Math.max.apply(0, [1,2,3]);
</script>
</body>
</html>
،ﺪﺷﺎﺒﻧ ﯽﺷ ﮏﯾ apply() ﺪﺘﻣ ﻝﻭﺍ ﻥﺎﻣﻮﮔﺭﺁ ﺮﮔﺍ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭ