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>
ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ
ﻦﯾﺍ
ﺭﺍﺪﻘﻣ ﺪﯿﻧﺍﻮﺗ ﯽﻤﻧ ﺎﻤﺷ .ﺖﺳﺍ ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﮏﯾ .ﺖﺴﯿﻧ ﺮﯿ :ﺪﯿﻨﯿﺒﺑ ﻦﯿﻨﭽﻤﻫ
.ﺩﺍﺩ ﻡﺎﺠﻧﺍ ءﺎﯿﺷﺍ ﯼﻭﺭ ﻥﺍﻮﺗ ﯽﻣ ﻪﮐ ﺪﻨﺘﺴﻫ ﯽﺗﺎﻣﺍﺪﻗﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫﺪﺘﻣ
ﺖﺳﺍ ﻊﺑﺎﺗ ﮏﯾ ﯼﻭﺎﺣ ﻪﮐ ﺖﺳﺍ ﯽﮔﮋﯾﻭ ﮏﯾ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺵﻭﺭ ﮏﯾ
ﻥﺎﺟ
ﻥﺯﻮﮔ
50
ﯽﺑﺁ
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>