ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ءﺎﯿﺷﺍ


فهرست مطالب

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


ﺎﻫ ﺵﻭﺭ ﻭ ﺎﻫ ﯽﮔﮋﯾﻭ ،ﯽﻌﻗﺍﻭ ﯽﮔﺪﻧﺯ ءﺎﯿﺷﺍ

.ﺖﺳﺍﯽﺷﮏﯾ ﻦﯿﺷﺎﻣ ،ﯽﻌﻗﺍﻭ ﯽﮔﺪﻧﺯ ﺭﺩ

:ﺖﺳﺍ ﻒﻗﻮﺗ ﻭ ﺕﺭﺎﺘﺳﺍ ﺪﻨﻧﺎﻣ ﯽﯾﺎﻫﺵﻭﺭ ﻭ ،ﮓﻧﺭ ﻭ ﻥﺯﻭ ﺪﻨﻧﺎﻣ ﺹﺍﻮﺧ ﯼﺍﺭﺍﺩ ﻭﺭﺩﻮﺧ ﮏﯾ

Object Properties Methods

car.name = Fiat

car.model = 500

car.weight = 850kg

car.color = white

car.start()

car.drive()

car.brake()

car.stop()

.ﺖﺳﺍ ﺕﻭﺎﻔﺘﻣ ﻒﻠﺘﺨﻣ ﯼﺎﻫﻭﺭﺩﻮﺧ ﺭﺩ ﯽﯾﺍﺭﺍﺩ ﯼﺎﻫﺵﺯﺭﺍ ﺎﻣﺍ ،ﺪﻧﺭﺍﺩ ﯽﻧﺎﺴﮑﯾ ﺹﺍﻮﺧ ﺎﻫﻭﺭﺩﻮﺧ ﻪﻤﻫ

ﺩﻮﺷ ﯽﻣ ﻡﺎﺠﻧﺍ ﺎﻫ ﺵﻭﺭ ﺎﻣﺍ ،ﺪﻧﺭﺍﺩ ﯽﻧﺎﺴﮑﯾ ﯼﺎﻫﺵﻭﺭﺎﻫﻭﺭﺩﻮﺧ ﻪﻤﻫ


ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ءﺎﯿﺷﺍ

ﺪﻨﺘﺴﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫﺮﯿﻐﺘﻣ ﻪﮐ ﺪﯾﺍ ﻪﺘﺧﻮﻣﺁ ﻼًﺒﻗ

ﺪﻫﺩ ﯽﻣ ﺹﺎﺼﺘﺧﺍ ﻥﺁ ﻪﺑ ﺍﺭ (Fiat)/>ﻩﺩﺎﺳ ﺭﺍﺪﻘﻣ ﮏﯾ ﺪﮐ ﻦﯾﺍ

let car = "Fiat";

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Variables</h2>

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

<script>
// Create and display a variable:
let car = "Fiat";
document.getElementById("demo").innerHTML = car;
</script>

</body>
</html>

ﺪﻨﺷﺎﺑ ﯼﺩﺎﯾﺯ ﺩﺭﺍﻮﻣ ﻞﻣﺎﺷ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ءﺎﯿﺷﺍ ﺎﻣﺍ .ﺪﻨﺘﺴﻫ ﺮﯿﻐﺘﻣ ﺰﯿﻧ ﺎﯿﺷﺍ

ﻪﺑ ﺍﺭ (Fiat, 500, white)/>ﯼﺩﺎﯾﺯ ﺮﯾﺩﺎﻘﻣ ﺪﮐ ﻦﯾﺍ

const car = {type:"Fiat", model:"500", color:"white"};

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Objects</h2>

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

<script>
// Create an object:
const car = {type:"Fiat", model:"500", color:"white"};

// Display some data from the object:
document.getElementById("demo").innerHTML = "The car type is " + car.type;
</script>

</body>
</html>

ﺪﻧﺍ ﻩﺪﺷ ﺍﺪﺟ ﻢﻫ ﺯﺍ a ﺎﺑ ﺭﺍﺪﻘﻣ ﻭ ﻡﺎﻧ) ﺪﻧﻮﺷ ﯽﻣ ﻪﺘﺷﻮﻧ name:value ﺖﻔﺟ ﺕﺭﻮﺻ ﻪﺑ ﺮﯾﺩﺎﻘﻣ

.ﺪﯿﻨﮐ ﻡﻼﻋﺍ const ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺎﺑ ﺍﺭ ﺎﯿﺷﺍ ﻪﮐ ﺖﺳﺍ ﻝﻮﻤﻌﻣ ﺵﻭﺭ ﮏﯾ ﻦﯾﺍ

.ﺪﯾﺯﻮﻣﺎﯿﺑ ﺮﺘﺸﯿﺑ JS Const :ﻞﺼﻓ ﺭﺩ ءﺎﯿﺷﺍ ﺎﺑ const ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻩﺭﺎﺑﺭﺩ



ﯽﺷ ﻒﯾﺮﻌﺗ

:(ﺪﯿﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﻭ) ﺪﯿﻨﮐ ﯽﻣ ﻒﯾﺮﻌﺗ ﻪﻤﻠﮐ ﯽﻌﻗﺍﻭ ﯼﺎﻨﻌﻣ ﻪﺑ ﯽﺷ ﮏﯾ ﺎﺑ ﺍﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺷ ﮏﯾ ﺎﻤﺷ

ﻝﺎﺜﻣ

const person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Objects</h2>

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

<script>
// Create an object:
const person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};

// Display some data from the object:
document.getElementById("demo").innerHTML =
person.firstName + " is " + person.age + " years old.";
</script>

</body>
</html>

:ﺩﺮﯿﮕﺑ ﺮﺑ ﺭﺩ ﺍﺭ ﻂﺧ ﻦﯾﺪﻨﭼ ﺪﻧﺍﻮﺗ ﯽﻣ ﯽﺷ ﻒﯾﺮﻌﺗ ﮏﯾ .ﺖﺴﯿﻧ ﻢﻬﻣ ﺖﺴﮑﺷ ﻁﻮﻄﺧ ﻭ ﺎﻫ ﻪﻠﺻﺎﻓ

ﻝﺎﺜﻣ

const person = {
    firstName: "John",
    lastName: "Doe",
  age: 50,
  eyeColor: "blue"
};

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Objects</h2>

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

<script>
// Create an object:
const person = {
  firstName: "John",
  lastName: "Doe",
  age: 50,
  eyeColor: "blue"
};

// Display some data from the object:
document.getElementById("demo").innerHTML =
person.firstName + " is " + person.age + " years old.";
</script>

</body>
</html>

ﯽﺷ ﯼﺎﻫ ﯽﮔﮋﯾﻭ

:ﺪﻧﻮﺷﯽﻣ ﻩﺪﯿﻣﺎﻧ ﺎﻫﯽﮔﮋﯾﻭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ءﺎﯿﺷﺍ ﺭﺩ name:values ﯼﺎﻫﺖﻔﺟ

firstName

ﻥﺎﺟ

lastName

ﻥﺯﻮﮔ

age

50

eyeColor

ﯽﺑﺁ


ﯽﺷ ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﻪﺑ ﯽﺳﺮﺘﺳﺩ

:ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﯽﺳﺮﺘﺳﺩ ﯽﺷ ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﻪﺑ ﺵﻭﺭ ﻭﺩ ﻪﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺎﻤﺷ

objectName.propertyName

ﺎﯾ

objectName["propertyName"]

1 ﻝﺎﺜﻣ

person.lastName;

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Objects</h2>

<p>There are two different ways to access an object property.</p>

<p>You can use person.property or person["property"].</p>

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

<script>
// Create an object:
const person = {
  firstName: "John",
  lastName : "Doe",
  id     :  5566
};

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

</body>
</html>


2 ﻝﺎﺜﻣ

person["lastName"];

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Objects</h2>

<p>There are two different ways to access an object property.</p>

<p>You can use person.property or person["property"].</p>

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

<script>
// Create an object:
const person = {
  firstName: "John",
  lastName : "Doe",
  id     :  5566
};

// Display some data from the object:
document.getElementById("demo").innerHTML =
person["firstName"] + " " + person["lastName"];
</script>

</body>
</html>


.ﺪﻧﻮﺷﯽﻣ ﻩﺪﯿﻣﺎﻧ ﺎﻫﯽﮔﮋﯾﻭ ﻪﮐ ﺪﻨﺘﺴﻫ ﻩﺪﺷ ﯼﺭﺍﺬﮔﻡﺎﻧ ﺮﯾﺩﺎﻘﻣ ﯼﺍﺮﺑ ﯽﯾﺎﻫﻪﻈﻔﺤﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ


ﯽﺷ ﯼﺎﻫ ﺵﻭﺭ

.ﺪﻨﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺵﻭﺭ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﻦﯿﻨﭽﻤﻫ ﺎﯿﺷﺍ

.ﺩﺍﺩ ﻡﺎﺠﻧﺍ ﺎﯿﺷﺍ ﯼﻭﺭ ﻥﺍﻮﺗﯽﻣ ﻪﮐ ﺪﻨﺘﺴﻫ ﯽﯾﺎﻫﻞﻤﻋ ﺎﻫﺵﻭﺭ

ﺪﻧﻮﺷ ﯽﻣ ﻩﺮﯿﺧﺫfunction> ﻥﺍﻮﻨﻋ ﻪﺑ ﺎﻫ ﯽﮔﮋﯾﻭ ﺭﺩ ﺎﻫﺪﺘﻣ

firstName

ﻥﺎﺟ

lastName

ﻥﺯﻮﮔ

age

50

eyeColor

ﯽﺑﺁ

fullName

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

.ﺩﻮﺷ ﯽﻣ ﻩﺮﯿﺧﺫ ﯽﮔﮋﯾﻭ ﮏﯾ ﻥﺍﻮﻨﻋ ﻪﺑ ﻪﮐ ﺖﺳﺍ ﯽﻌﺑﺎﺗ ﺪﺘﻣ


ﻝﺎﺜﻣ

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

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

I.E. this.firstName ﯽﮔﮋﯾﻭ ﯼﺎﻨﻌﻣ ﻪﺑ firstName this ﺖﺳﺍ.

I.E. this.firstName ﯽﮔﮋﯾﻭ ﯼﺎﻨﻌﻣ ﻪﺑ firstName person ﺖﺳﺍ.


ﻦﯾﺍ ؟ﺖﺴﯿﭼ

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

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

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

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

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

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

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

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

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

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

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


ﻦﯾﺍ ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ

.ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﻊﺑﺎﺗ "ﮏﻟﺎﻣ" ﻪﺑ this ،ﻊﺑﺎﺗ ﻒﯾﺮﻌﺗ ﺭﺩ

"ﮏﻟﺎﻣ" ﻪﮐ ﺖﺳﺍ ﯽﺼﺨﺷ ءﯽﺷ ﻦﯾﺍ<"code class="w3-codespan> ،ﻻﺎﺑ ﻝﺎﺜﻣ ﺭﺩ

.ﺖﺳﺍ ﯽﺷ ﻦﯾﺍfirstName ﯽﮔﮋﯾﻭ ﯼﺎﻨﻌﻣ ﻪﺑ this

.ﺪﯾﺯﻮﻣﺎﯿﺑ ﺮﺘﺸﯿﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺵﺯﻮﻣﺁ ﻦﯾﺍ ﺭﺩ ﻦﯾﺍ<"code class="w3-codespan> ﻩﺭﺎﺑﺭﺩ


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

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

objectName.methodName()

ﻝﺎﺜﻣ

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 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>

ﺍﺭ ﻥﺁ ،ﺪﯾﺭﺍﺩ ﯽﺳﺮﺘﺳﺩ() ﺰﺘﻧﺍﺮﭘ ﻥﻭﺪﺑ ﯽﺷﻭﺭ ﻪﺑ ﺮﮔﺍ

ﻝﺎﺜﻣ

name = person.fullName;

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

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Objects</h2>

<p>If you access an object method without (), it will return the function definition:</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>

!ﺪﯿﻨﮑﻧ ﻡﻼﻋﺍ ﺎﯿﺷﺍ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﺎﻫ ﯽﻟﻮﺑ ﻭ ﺩﺍﺪﻋﺍ ،ﺎﻫ ﻪﺘﺷﺭ

ﺮﯿﻐﺘﻣ ،ﺩﻮﺷ ﯽﻣ ﻥﻼﻋﺍ new" ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺎﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺮﯿﻐﺘﻣ ﮏﯾ ﯽﺘﻗﻭ

x = new String();        // Declares x as a String object
y = new Number();        // Declares y as a Number object
z = new Boolean();       // Declares z as a Boolean object

ﺪﻨﻫﺩ ﯽﻣ ﺶﻫﺎﮐ ﺍﺭ ﺖﻋﺮﺳ ﻭ ﺪﻨﻨﮐ ﯽﻣ ﻩﺪﯿﭽﯿﭘ ﺍﺭ ﺎﻤﺷ ﺪﮐ ﺎﻬﻧﺁ . .ﺪﯿﻨﮐ ﺏﺎﻨﺘﺟﺍ Boolean

.ﺖﺧﻮﻣﺁ ﺪﯿﻫﺍﻮﺧ ﺮﺘﺸﯿﺑ ﺎﯿﺷﺍ ﺩﺭﻮﻣ ﺭﺩ ﺵﺯﻮﻣﺁ ﻦﯾﺍ ﻪﻣﺍﺩﺍ ﺭﺩ



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