ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﺱﻼﮐ


فهرست مطالب

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

ECMAScript 2015 ﻡﺎﻧ ﺎﺑ ﻪﮐ ES6 ﺩﺮﮐ ﯽﻓﺮﻌﻣ ﺍﺭ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﺱﻼﮐ ،ﺩﻮﺷ ﯽﻣ ﻪﺘﺧﺎﻨﺷ ﺰﯿﻧ.

.ﺪﻨﺘﺴﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ءﺎﯿﺷﺍ ﯼﺍﺮﺑ ﯽﯾﺎﻫ ﺐﻟﺎﻗ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﺱﻼﮐ

ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺱﻼﮐ ﻮﺤﻧ

.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ class ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺯﺍ ﺱﻼﮐ ﺩﺎﺠﯾﺍ ﯼﺍﺮﺑ

:ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ constructor() ﻡﺎﻧ ﻪﺑ ﯽﺷﻭﺭ ﻪﺸﯿﻤﻫ

ﻮﺤﻧ

class ClassName {
   constructor() { ... }
}

ﻝﺎﺜﻣ

class Car {
   constructor(name, year) {
    this.name = name;
    this.year = year;
  }
}

.ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ "Car" ﻡﺎﻧ ﻪﺑ ﯽﺳﻼﮐ ﻻﺎﺑ ﻝﺎﺜﻣ

."year" ﻭ "name" :ﺖﺳﺍ ﻪﯿﻟﻭﺍ ﯽﮔﮋﯾﻭ ﻭﺩ ﯼﺍﺭﺍﺩ ﺱﻼﮐ

.ﺖﺳﺍ ﺖﺴﯿﻧ ﯽﺷ ﮏﯾ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺱﻼﮐ

.ﺖﺳﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ءﺎﯿﺷﺍ ﯼﺍﺮﺑ ﻮﮕﻟﺍ ﮏﯾ ﻦﯾﺍ


ﺱﻼﮐ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ

:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ءﺎﯿﺷﺍ ﺩﺎﺠﯾﺍ ﯼﺍﺮﺑ ﺱﻼﮐ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ،ﺪﯾﺭﺍﺩ ﺱﻼﮐ ﮏﯾ ﻪﮐ ﯽﻣﺎﮕﻨﻫ

ﻝﺎﺜﻣ

const myCar1 = new Car("Ford", 2014);
const myCar2 = new Car("Audi", 2019);

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

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Classes</h1>
<p>Creating two car objects from a car class:</p>

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

<script>
class Car {
  constructor(name, year) {
    this.name = name;
    this.year = year;
  }
}

const myCar1 = new Car("Ford", 2014);
const myCar2 = new Car("Audi", 2019);

document.getElementById("demo").innerHTML =
myCar1.name + " " + myCar2.name;
</script>

</body>
</html>

.ﺪﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ Car object ﻭﺩ ﺩﺎﺠﯾﺍ ﯼﺍﺮﺑ Car class ﺯﺍ ﻻﺎﺑ ﻝﺎﺜﻣ

.ﺩﻮﺷ ﯽﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺭﺎﮐﺩﻮﺧ ﺭﻮﻃ ﻪﺑ ﺩﻮﺷ ﯽﻣ ﺩﺎﺠﯾﺍ ﺪﯾﺪﺟ ﯽﺷ ﮏﯾ ﻪﮐ ﯽﻣﺎﮕﻨﻫ ﻩﺪﻧﺯﺎﺳ ﺪﺘﻣ


ﻩﺪﻧﺯﺎﺳ ﺵﻭﺭ

:ﺖﺳﺍ ﺹﺎﺧ ﺵﻭﺭ ﮏﯾ ﻩﺪﻧﺯﺎﺳ ﺵﻭﺭ

  • .ﺪﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺍﺭ "ﻩﺪﻧﺯﺎﺳ" ﻖﯿﻗﺩ ﻡﺎﻧ ﺪﯾﺎﺑ

  • ﺩﻮﺷ ﯽﻣ ﺍﺮﺟﺍ ﺭﺎﮐﺩﻮﺧ ﺭﻮﻃ ﻪﺑ ﺩﻮﺷ ﯽﻣ ﺩﺎﺠﯾﺍ ﺪﯾﺪﺟ ﯽﺷ ﮏﯾ ﻪﮐ ﯽﻣﺎﮕﻨﻫ

  • ﺩﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﯽﺷ ﺕﺎﯿﺻﻮﺼﺧ ﻪﯿﻟﻭﺍ ﯽﻫﺩﺭﺍﺪﻘﻣ ﯼﺍﺮﺑ

ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ،ﺪﯿﻨﮑﻧ ﻒﯾﺮﻌﺗ ﺍﺭ ﻩﺪﻧﺯﺎﺳ ﺪﺘﻣ ﺮﮔﺍ



ﺱﻼﮐ ﯼﺎﻫ ﺵﻭﺭ

.ﺪﻧﻮﺷ ﯽﻣ ﺩﺎﺠﯾﺍ ﯽﺷ ﯼﺎﻫﺪﺘﻣ ﻪﺑﺎﺸﻣ ﺲﮑﺘﻨﯿﺳ ﺎﺑ ﺱﻼﮐ ﯼﺎﻫﺪﺘﻣ

.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ class ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺯﺍ ﺱﻼﮐ ﺩﺎﺠﯾﺍ ﯼﺍﺮﺑ

.ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ constructor() ﺵﻭﺭ ﮏﯾ ﻪﺸﯿﻤﻫ

.ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﺍﺭ ﺵﻭﺭ ﺩﺍﺪﻌﺗ ﺮﻫ ﺲﭙﺳ

ﻮﺤﻧ

class ClassName {
   constructor() { ... }
  method_1() { ... }
  method_2() { ... }
  method_3() { ... }
}

:ﺪﻧﺍﺩﺮﮔ ﯽﻣﺮﺑ ﺍﺭ ﻭﺭﺩﻮﺧ ﻦﺳ ﻪﮐ ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ "age" ﻡﺎﻧ ﻪﺑ ﺱﻼﮐ ﺪﺘﻣ ﮏﯾ

ﻝﺎﺜﻣ

class Car {
   constructor(name, year) {
    this.name = name;
    this.year = year;
   }
  age() {
    const date = new Date();
    return date.getFullYear() - this.year;
   }
}

const myCar = new Car("Ford", 2014);
document.getElementById("demo").innerHTML =
"My car is " + myCar.age() + " years old.";

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

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Class Methods</h1>
<p>How to define and use a Class method.</p>

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

<script>
class Car {
  constructor(name, year) {
    this.name = name;
    this.year = year;

  }
  age() {
    const date = new Date();
    return date.getFullYear() - this.year;
  }
}

const myCar = new Car("Ford", 2014);
document.getElementById("demo").innerHTML =
"My car is " + myCar.age() + " years old.";
</script>

</body>
</html>

:ﺪﯿﻨﮐ ﻝﺎﺳﺭﺍ ﺱﻼﮐ ﯼﺎﻫﺪﺘﻣ ﻪﺑ ﺍﺭ ﺎﻫﺮﺘﻣﺍﺭﺎﭘ ﺪﯿﻧﺍﻮﺗ ﯽﻣ

ﻝﺎﺜﻣ

class Car {
  constructor(name, year) {
    
  this.name = name;
    this.year = year;
  }
  
  age(x) {
    return x - this.year;
  }
}

  const date = new Date();
  let year = date.getFullYear();
const myCar = new 
  Car("Ford", 2014);
document.getElementById("demo").innerHTML=
"My car is 
  " + myCar.age(year) + " years old."; 

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

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Class Method</h1>
<p>Pass a parameter into the "age()" method.</p>

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

<script>
class Car {
  constructor(name, year) {
    this.name = name;
    this.year = year;
  }
  age(x) {
    return x - this.year;
  }
}

const date = new Date();
let year = date.getFullYear();

const myCar = new Car("Ford", 2014);
document.getElementById("demo").innerHTML=
"My car is " + myCar.age(year) + " years old.";
</script>

</body>
</html>

ﺮﮔﺭﻭﺮﻣ ﯽﻧﺎﺒﯿﺘﺸﭘ

ﺪﻨﮐ ﯽﻣ ﻒﯾﺮﻌﺗ ﻥﺁ ﺯﺍ ﻞﻣﺎﮐ ﯽﻧﺎﺒﯿﺘﺸﭘ ﺎﺑ ﺍﺭ ﺮﮔﺭﻭﺮﻣ ﻪﺨﺴﻧ ﻦﯿﻟﻭﺍ ﺮﯾﺯ ﻝﻭﺪﺟ

Chrome 49 Edge 12 Firefox 45 Safari 9 Opera 36
Mar, 2016 Jul, 2015 Mar, 2016 Oct, 2015 Mar, 2016

.ﺖﺧﻮﻣﺁ ﺪﯿﻫﺍﻮﺧ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫ ﺱﻼﮐ ﺩﺭﻮﻣ ﺭﺩ ﯼﺮﺘﺸﯿﺑ ﺕﺎﻋﻼﻃﺍ ﺵﺯﻮﻣﺁ ﻦﯾﺍ ﺭﺩ ﺍًﺪﻌﺑ

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