() ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻊﺑﺎﺗ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺵﻭﺭ


فهرست مطالب

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


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

.ﺪﺷﺎﺑ ﻩﺩﺎﻔﺘﺳﺍ ﻞﺑﺎﻗ ﻒﻠﺘﺨﻣ ﺩﺭﺍﻮﻣ ﺭﺩ ﻪﮐ ﺪﯿﺴﯾﻮﻨﺑ ﯼﺪﺘﻣ ﺪﯿﻧﺍﻮﺗﯽﻣ ، ﺪﻨﺘﺴﻫ ﺵﻭﺭ ﻊﺑﺍﻮﺗ ﻪﻤﻫ

.ﺪﻨﺘﺴﻫ ﯽﺷ ﯼﺎﻫﺪﺘﻣ ﻊﺑﺍﻮﺗ ﻪﻤﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ

ﺖﺳﺍ ﯽﺷ ﺯﺍ ﯽﻌﺑﺎﺗ ،ﺪﺷﺎﺒﻧ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﮏﯾ ﺪﺘﻣ ﻊﺑﺎﺗ ﮏﯾ ﺮﮔﺍ

ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ 3 ﺎﺑ ﯽﺷ ﮏﯾ ﺮﯾﺯ ﻝﺎﺜﻣ

ﻝﺎﺜﻣ

const person = {
  firstName:"John",
  lastName: "Doe",
    fullName: function () {
    return this.firstName + " " + this.lastName;
    }
}

// This will return "John Doe":
person.fullName();  

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Functions</h2>

<p>This example creates an object with 3 properties (firstName, lastName, fullName).</p>
<p>The fullName property is a method:</p> 

<p id="demo"></p>

<script>
const myObject = {
  firstName:"John",
  lastName: "Doe",
  fullName: function() {
    return this.firstName + " " + this.lastName;
  }
}
document.getElementById("demo").innerHTML = myObject.fullName();
</script>

</body>
</html>


.ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﺺﺨﺷ ءﯽﺷ ﻪﺑ this ،ﻻﺎﺑ ﻝﺎ

this.firstName ﯽﮔﮋﯾﻭ ﯼﺎﻨﻌﻣ ﻪﺑ firstName thi

:ﻞﺜﻣ

this.firstName ﯽﮔﮋﯾﻭ ﯼﺎﻨﻌﻣ ﻪﺑ firstName per


ﻦﯾﺍ ؟ﺖﺴﯿﭼ

.ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﺷ ﮏﯾ ﻪﺑ this ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ،ﺖﭙﯾﺮﮑﺳﺍ

ﻡﺍﺪﮐ (ﯽﻧﺍﻮﺧﺍﺮﻓ ﺎﯾ ﻩﺩﺎﻔﺘﺳﺍ) ﯽﻧﺍﻮﺧﺍﺮﻓ ﻩﻮﺤﻧ ﻪﺑ ﯽﮕﺘﺴﺑ ﯽﺷ

:ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﻔﻠﺘﺨﻣ ءﺎﯿﺷﺍ ﻪﺑ ﻥﺁ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻩﻮﺤﻧ ﻪﺑ ﻪﺘﺴﺑ this

  • .ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﺷ ﻪﺑ ﻦﯾﺍ<"code class="w3-codespan> ،ﯽﺷ ﺵﻭﺭ ﮏﯾ ﺭﺩ

  • .ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﻧﺎﻬﺟ ءﯽﺷ ﻪﺑ ﻦﯾﺍ<"code class="w3-codespan> ،ﯽﯾﺎﻬﻨﺗ ﻪﺑ

  • .ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﻧﺎﻬﺟ ءﯽﺷ ﻪﺑ ﻦﯾﺍ<"code class="w3-codespan> ،ﻊﺑﺎﺗ ﮏﯾ ﺭﺩ

  • .ﺖﺳﺍ ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ<"code>

    ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ

    ﻦﯾﺍ ﺭﺍﺪﻘﻣ ﺪﯿﻧﺍﻮﺗ ﯽﻤﻧ ﺎﻤﺷ .ﺖﺳﺍ ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﮏﯾ .ﺖﺴﯿﻧ ﺮﯿ

    :ﺪﯿﻨﯿﺒﺑ ﻦﯿﻨﭽﻤﻫ

    ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻦﯾﺍ ﺵﺯﻮﻣﺁ



ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ() ﯽﻧﺍﻮﺧﺍﺮﻓ ﺵﻭﺭ

ﺖﺳﺍ ﻩﺪﺷ ﻒﯾﺮﻌﺗ ﺶﯿﭘ ﺯﺍ ﺵﻭﺭ ﮏﯾ call() ﺵﻭﺭ

ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺪﺘﻣ ﮏﯾ ﯽﻧﺍﻮﺧﺍﺮﻓ ﯼﺍﺮﺑ ﻥﺁ ﺯﺍ ﻥﺍﻮﺗ ﯽﻣ

.ﺪﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺮﮕﯾﺩ ﯽﺷ ﮏﯾ ﻪﺑ ﻖﻠﻌﺘﻣ ﯼﺪﺘﻣ ﺯﺍ ﺪﻧﺍﻮﺗ ﯽﻣ ﯽﺷ ﮏﯾ ،ca

ﺪﻨﮐﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺍﺭ ﺩﺮﻓ fullName ﺵﻭﺭ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﻝﺎﺜﻣ ﻦﯾﺍ

ﻝﺎﺜﻣ

const person = {
    fullName: function() {
    return this.firstName + " " + this.lastName;
    }
}
const person1 = {
  firstName:"John",
    lastName: "Doe"
  }
const person2 = {
  firstName:"Mary",
    lastName: "Doe"
}

// This will return "John Doe":
  
  person.fullName.call(person1);

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!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() {
    return this.firstName + " " + this.lastName;
  }
}
const person1 = {
  firstName:"John",
  lastName: "Doe"
}
const person2 = {
  firstName:"Mary",
  lastName: "Doe"
}
document.getElementById("demo").innerHTML = person.fullName.call(person1); 
</script>

</body>
</html>


ﺪﻨﮐﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺍﺭ ﺩﺮﻓ fullName ﺵﻭﺭ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﻝﺎﺜﻣ ﻦﯾﺍ

ﻝﺎﺜﻣ

const person = {
    fullName: function() {
      return this.firstName + " " + this.lastName;
    }
}
const person1 = {
  firstName:"John",
    lastName: "Doe"
  }
const person2 = {
    firstName:"Mary",
    lastName: "Doe"
}

// This will return "Mary Doe"
  person.fullName.call(person2);

→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Functions</h2>
<p>This example calls the fullName method of person, using it on person2:</p>

<p id="demo"></p>

<script>
const person = {
  fullName: function() {
    return this.firstName + " " + this.lastName;
  }
}
const person1 = {
  firstName:"John",
  lastName: "Doe"
}
const person2 = {
  firstName:"Mary",
  lastName: "Doe"
}
document.getElementById("demo").innerHTML = person.fullName.call(person2); 
</script>

</body>
</html>


ﺎﻫ ﻥﺎﻣﻮﮔﺭﺁ ﺎﺑ()call ﺪﺘﻣ

:ﺩﺮﯾﺬﭙﺑ ﺍﺭ ﺎﻫﻥﺎﻣﻮﮔﺭﺁ ﺪﻧﺍﻮﺗﯽﻣ 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>


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