ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﺵﻭﺭ


فهرست مطالب

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


ﻝﺎﺜﻣ

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

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

<!DOCTYPE html>
<html>
<body>

<h1>The JavaScript <i>this</i> Keyword</h1>
<p>In this example, <b>this</b> refers to the <b>person</b> object.</p>
<p>Because <b>fullName</b> is a method of the person object.</p>

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

<script>
// Create an object:
const person = {
  firstName: "John",
  lastName: "Doe",
  id: 5566,
  fullName : function() {
    return this.firstName + " " + this.lastName;
  }
};

// Display data from the object:
document.getElementById("demo").innerHTML = person.fullName();
</script>

</body>
</html>

ﻦﯾﺍ ؟ﺖﺴﯿﭼ

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

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

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

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

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

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

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

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

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

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

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


ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﺵﻭﺭ

.ﺩﺍﺩ ﻡﺎﺠﻧﺍ ءﺎﯿﺷﺍ ﯼﻭﺭ ﻥﺍﻮﺗ ﯽﻣ ﻪﮐ ﺪﻨﺘﺴﻫ ﯽﺗﺎﻣﺍﺪﻗﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫﺪﺘﻣ

ﺖﺳﺍ ﻊﺑﺎﺗ ﮏﯾ ﯼﻭﺎﺣ ﻪﮐ ﺖﺳﺍ ﯽﮔﮋﯾﻭ ﮏﯾ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺵﻭﺭ ﮏﯾ

firstName

ﻥﺎﺟ

lastName

ﻥﺯﻮﮔ

age

50

eyeColor

ﯽﺑﺁ

fullName

function() {return this.firstName + " " + this.lastName;}

.ﺪﻧﻮﺷ ﯽﻣ ﻩﺮﯿﺧﺫ ﯽﺷ ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﻥﺍﻮﻨﻋ ﻪﺑ ﻪﮐ ﺪﻨﺘﺴﻫ ﯽﻌﺑﺍﻮﺗ ﺎﻫﺪﺘﻣ


ﯽﺷ ﯼﺎﻫ ﺵﻭﺭ ﻪﺑ ﯽﺳﺮﺘﺳﺩ

:ﺪﯾﺭﺍﺩ ﯽﺳﺮﺘﺳﺩ ﺮﯾﺯ ﻮﺤﻧ ﺎﺑ ﯽﺷ ﺪﺘﻣ ﮏﯾ ﻪﺑ ﺎﻤﺷ

objectName.methodName()

ﻭ ﺪﯿﻨﮐ ﯽﻣ ﻒﯿﺻﻮﺗ ﺺﺨﺷ ﯽﺷ ﺯﺍ ﯼﺪﺘﻣ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ()fullName ﻻًﻮﻤﻌﻣ ﺎﻤﺷ

.ﺩﻮﺷ ﯽﻣ ﺍﺮﺟﺍ (ﻊﺑﺎﺗ ﮏﯾ ﻥﺍﻮﻨﻋ ﻪﺑ) ﺩﻮﺷ ﯽﻧﺍﻮﺧﺍﺮﻓ() ﺎﺑ ﻪﮐ ﯽﻣﺎﮕﻨﻫ fullName ﯽﮔﮋﯾﻭ

:ﺩﺭﺍﺩ ﯽﺳﺮﺘﺳﺩ ﺺﺨﺷ ﯽﺷ ﮏﯾ()strong> fullName/>ﺵﻭﺭ ﻪﺑ ﻝﺎﺜﻣ ﻦﯾﺍ

ﻝﺎﺜﻣ

name = person.fullName();

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Objects</h2>
<p>Creating and using an object method.</p>
<p>A method is actually a function definition stored as a property value.</p>

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

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

document.getElementById("demo").innerHTML = person.fullName();
</script>
</body>
</html>

ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﯽﺳﺮﺘﺳﺩ fullName/>ﯽﮔﮋﯾﻭ ﻪﺑ ،() ﻥﻭﺪﺑ ﺮﮔﺍ

ﻝﺎﺜﻣ

name = person.fullName;

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Objects</h2>
<p>An object method is a function definition stored as a property value.</p>
<p>If you access it without (), it will return the function definition:</p>

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

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

document.getElementById("demo").innerHTML = person.fullName;
</script>
</body>
</html>


ﯽﺷ ﮏﯾ ﻪﺑ ﺪﺘﻣ ﻥﺩﻭﺰﻓﺍ

:ﺖﺳﺍ ﻥﺎﺳﺁ ﯽﺷ ﮏﯾ ﻪﺑ ﺪﯾﺪﺟ ﺵﻭﺭ ﮏﯾ ﻥﺩﻭﺰﻓﺍ

ﻝﺎﺜﻣ

 person.name = function () {
  return this.firstName + " " + this.lastName;
};

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Objects</h2>
<p id="demo"></p>

<script>
const person = {
  firstName: "John",
  lastName: "Doe",
  id: 5566,
};
person.name = function() {
  return this.firstName + " " + this.lastName;
};

document.getElementById("demo").innerHTML =
"My father is " + person.name(); 
</script>

</body>
</html>

ﯽﻠﺧﺍﺩ ﯼﺎﻫ ﺵﻭﺭ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ

.ﺪﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻦﺘﻣ ﮏﯾ ﻞﯾﺪﺒﺗ ﯼﺍﺮﺑ String ﯽﺷ toUpperCase()

let message = "Hello world!";
let x = message.toUpperCase();

:ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﺮﯾﺯ ﺕﺭﻮﺻ ﻪﺑ ﻻﺎﺑ ﺪﮐ ﯼﺍﺮﺟﺍ ﺯﺍ ﺲﭘ x ﺭﺍﺪﻘﻣ

HELLO WORLD!

ﻝﺎﺜﻣ

person.name = function () {
  return (this.firstName + " " + this.lastName).toUpperCase();
};

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Objects</h2>
<p id="demo"></p>

<script>
const person = {
  firstName: "John",
  lastName: "Doe",
  id: 5566,
};
person.name = function() {
  return (this.firstName + " " + this.lastName).toUpperCase();
};

document.getElementById("demo").innerHTML =
"My father is " + person.name(); 
</script>

</body>
</html>

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