ﺪﺘﻣ() ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻊﺑﺎﺗ


فهرست مطالب

    نمایش فهرست مطالب


ﺩﺪﺠﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺵﻭﺭ

.ﺪﺷﺎﺑ ﻩﺩﺎﻔﺘﺳﺍ ﻞﺑﺎﻗ ﻒﻠﺘﺨﻣ ﺩﺭﺍﻮﻣ ﺭﺩ ﻪﮐ ﺪﯿﺴﯾﻮﻨﺑ ﯼﺪﺘﻣ ﺪﯿﻧﺍﻮﺗﯽﻣ ، ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ apply() ﺵﻭﺭ

.ﺖﺳﺍ (ﯽﻠﺒﻗ ﻞﺼﻓ) call() ﺵﻭﺭ ﻪﺑﺎﺸﻣ

ﻝﺎﺜﻣ

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>




ﺎﻫ ﻪﯾﺍﺭﺁ ﯼﻭﺭ Max ﺵﻭﺭ ﮏﯾ ﯼﺯﺎﺳ ﻪﯿﺒﺷ

:ﺪﯿﺑﺎﯿﺑ (ﺩﺍﺪﻋﺍ ﺖﺴﯿﻟ ﺭﺩ) ﺍﺭ ﺩﺪﻋ ﻦﯾﺮﺘﮔﺭﺰﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ 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() ﺪﺘﻣ ﻝﻭﺍ ﻥﺎﻣﻮﮔﺭﺁ ﺮﮔﺍ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭ

تمامی حقوق محفوظ است. © BasicIT.org • 2023-2024