ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺱﻼﮐ ﺖﺛﺍﺭﻭ


فهرست مطالب

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


ﯽﺗﺎﻘﺒﻃ ﺖﺛﺍﺭﻭ

.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ extends ﺯﺍ ،ﺱﻼﮐ ﺖﺛﺍﺭﻭ ﺩﺎﺠﯾﺍ ﯼﺍﺮﺑ

ﺩﺮﺑ ﯽﻣ ﺙﺭﺍ ﻪﺑ ﻥﺁ ﺯﺍ ﺍﺭ ﺎﻫﺪﺘﻣ ﻡﺎﻤﺗ ،ﺖﺳﺍ ﻩﺪﺷ ﺩﺎﺠﯾﺍ ﺱﻼﮐ ﺖﺛﺍﺭﻭ ﺎﺑ ﻪﮐ ﯽﺳﻼﮐ

ﻝﺎﺜﻣ

.ﺩﺮﺑ ﯽﻣ ﺙﺭﺍ ﻪﺑ "Car" ﺯﺍ ﺍﺭ ﺎﻫﺪﺘﻣ ﻪﮐ ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ "Model" ﻡﺎﻧ ﻪﺑ ﺱﻼﮐ ﮏﯾ

class Car {
  constructor(brand) {
    this.carname = 
  brand;	  }
  present() {
    return 'I have a ' + this.carname;	  }
}
class Model extends Car {	  constructor(brand, mod) {
    super(brand);
    this.model = mod;	  }
  show() {
   
      return this.present() + ', it is a ' + this.model;	  }
}
let myCar = new Model("Ford", "Mustang");
document.getElementById("demo").innerHTML 
  = myCar.show();

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

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Class Inheritance</h1>

<p>Use the "extends" keyword to inherit all methods from another class.</p>
<p>Use the "super" method to call the parent's constructor function.</p>

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

<script>
class Car {
  constructor(brand) {
    this.carname = brand;
  }
  present() {
    return 'I have a ' + this.carname;
  }
}

class Model extends Car {
  constructor(brand, mod) {
    super(brand);
    this.model = mod;
  }
  show() {
    return this.present() + ', it is a ' + this.model;
  }
}

const myCar = new Model("Ford", "Mustang");
document.getElementById("demo").innerHTML = myCar.show();
</script>

</body>
</html>

ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﺪﻟﺍﻭ ﻪﺑ super() ﺵﻭﺭ

ﺭﺩ super() ﺪﺘﻣ ﯽﻧﺍﻮﺧﺍﺮﻓ ﺎﺑ

.ﺪﯿﻨﮐ ﺩﺪﺠﻣ ﻩﺩﺎﻔﺘﺳﺍ ﺩﻮﺟﻮﻣ ﺱﻼﮐ ﮏﯾ ﯼﺎﻫ ﺵﻭﺭ ﻭ ﺎﻫ ﯽﮔﮋﯾﻭ ﺯﺍ ،ﺪﯿﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﺪﯾﺪﺟ ﺱﻼﮐ ﮏﯾ ﻪﮐ ﯽ



ﺎﻫ ﻩﺪﻨﻨﮐ ﻢﯿﻈﻨﺗ ﻭ ﺎﻫ ﻩﺪﻨﻨﮐ ﺖﻓﺎﯾﺭﺩ

.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺎﻫﺮﺘﺘﺳ ﻭ ﺎﻫﺮﯿﮔ ﺯﺍ ﺪﻫﺩ ﯽﻣ ﻥﺎﮑﻣﺍ ﺎﻤﺷ ﻪﺑ ﻦﯿﻨﭽﻤﻫ ﺎﻫ ﺱﻼﮐ

ﺮﮔﺍ ﺹﻮﺼﺧ ﻪﺑ ،ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺩﻮﺧ ﺹﺍﻮﺧ ﯼﺍﺮﺑ ﺎﻫﺮﺘﺳ ﻭ ﺎﻫ ﻩﺪﻧﺮﯿﮔ ﺯﺍ ﻪﮐ ﺪﺷﺎﺑ ﻪﻧﺍﺪﻨﻤﺷﻮﻫ ﺪﻧﺍﻮﺗ

ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ <"code class="w3-codespan> ﺯﺍ ،ﺱﻼﮐ ﺭﺩ ﻩﺪﻨﻨﮐ ﻢﯿﻈﻨﺗ ﻭ ﻩﺪﻧﺮﯿﮔ ﻥﺩﻭﺰﻓﺍ ﯼﺍﺮﺑ

ﻝﺎﺜﻣ

:ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ "carname" ﯽﮔﮋﯾﻭ ﯼﺍﺮﺑ ﻩﺪﻨﻨﮐ ﻢﯿﻈﻨﺗ ﮏﯾ ﻭ ﻩﺪﻧﺮﯿﮔ ﮏﯾ

 class Car {
  constructor(brand) {
    this.carname 
  = brand;
  }
  get cnam() {
    
  return this.carname;
  }
  set cnam(x) {
    
  this.carname = x;
  }
}
const myCar = new Car("Ford");

  document.getElementById("demo").innerHTML = myCar.cnam;

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

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Class Getter/Setter</h1>
<p>A demonstration of how to add getters and setters in a class, and how to use the getter to get the property value.</p>

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

<script>
class Car {
  constructor(brand) {
    this.carname = brand;
  }
  get cnam() {
    return this.carname;
  }
  set cnam(x) {
    this.carname = x;
  }
}

const myCar = new Car("Ford");

document.getElementById("demo").innerHTML = myCar.cnam;
</script>

</body>
</html>

ﻪﺟﻮﺗ: ﯽﻤﻧ ﻩﺩﺎﻔﺘﺳﺍ ﺰﺘﻧﺍﺮﭘ ﺯﺍ ،ﺪﺷﺎﺑ ﺵﻭﺭ ﮏﯾ ﻩﺪﻧﺮﯿﮔ ﺮﮔﺍ ﯽﺘﺣﺪﯿﻨﮐ.

ﺪﺷﺎﺑ ﯽﮑﯾ the ﻡﺎﻧ ﺎﺑ ﺪﻧﺍﻮﺗ ﯽﻤﻧ getter/setter ﺪﺘﻣ ﻡﺎﻧ

<p>ﻂﺧ ﺮﯾﺯ ﺮﺘﮐﺍﺭﺎﮐ ﮏﯾ ﺯﺍ ﻥﺎﺴﯾﻮﻧ ﻪﻣﺎﻧﺮﺑ ﺯﺍ ﯼﺭﺎﯿﺴﺑ _ ﺪﻨ

ﻝﺎﺜﻣ

ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺖﻣﻼﻋ ﺯﺍ ﻩﺪﻨﻨﮐ ﻢﯿﻈﻨﺗ /ﻩﺪﻧﺮﯿﮔ ﻥﺩﺮﮐ ﺍﺪﺟ ﯼﺍﺮﺑ ﻂﺧ ﺮﯾﺯ ﺮﺘﮐﺍﺭﺎﮐ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ

 class Car {
  constructor(brand) {
    this._carname 
  = brand;
  }
  get carname() {
    
  return this._carname;
  }
  set carname(x) {
    
  this._carname = x;
  }
}
const myCar = new Car("Ford");

  document.getElementById("demo").innerHTML = myCar.carname;

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

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Class Getter/Setter</h1>
<p>Using an underscore character is common practice when using getters/setters in JavaScript, but not mandatory, you can name them anything you like, but not the same as the property name.</p>

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

<script>
class Car {
  constructor(brand) {
    this._carname = brand;
  }
  get carname() {
    return this._carname;
  }
  set carname(x) {
    this._carname = x;
  }
}

const myCar = new Car("Ford");

document.getElementById("demo").innerHTML = myCar.carname;
</script>

</body>
</html>

:ﺰﺘﻧﺍﺮﭘ ﻥﻭﺪﺑ ،ﺪﯿﻨﮐﯽﻣ ﻢﯿﻈﻨﺗ ﺍﺭ ﺖﯿﺻﺎﺧ ﺭﺍﺪﻘﻣ ﻪﮐ ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﯼﻮﺤﻧ ﻥﺎﻤﻫ ﺯﺍ ،ﻩﺪﻨ

ﻝﺎﺜﻣ

:ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ "Volvo" ﻪﺑ ﻭﺭﺩﻮﺧ ﻡﺎﻧ ﺮﯿﯿﻐﺗ ﯼﺍﺮﺑ ﻩﺪﻨﻨﮐ ﻢﯿﻈﻨﺗ ﮏﯾ ﺯﺍ

 class Car {
  constructor(brand) {
    this._carname 
  = brand;
  }
  get carname() {
    
  return this._carname;
  }
  set carname(x) {
    
  this._carname = x;
  }
}
const myCar = new Car("Ford");
  myCar.carname = "Volvo";
  document.getElementById("demo").innerHTML = myCar.carname;

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

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Class Setters</h1>
<p>When using a setter to set a property value, you do not use parantheses.</p>

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

<script>
class Car {
  constructor(brand) {
    this._carname = brand;
  }
  set carname(x) {
    this._carname = x;
  }
  get carname() {
    return this._carname;
  }
}

const myCar = new Car("Ford");
myCar.carname = "Volvo";
document.getElementById("demo").innerHTML = myCar.carname;
</script>

</body>
</html>

ﻥﺩﺮﺑ ﻻﺎﺑ

.ﺪﻧﻭﺭﯽﻤﻧ ﻻﺎﺑ ﺱﻼﮐ ﯼﺎﻫﻥﻼﻋﺍ ،ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻫﻥﻼﻋﺍ ﺮﯾﺎﺳ ﻭ ﻊﺑﺍﻮﺗ ﻑﻼﺧﺮﺑ

:ﺪﯿﻨﮐ ﻡﻼﻋﺍ ﺍﺭ ﻥﺁ ﺪﯾﺎﺑ ﺱﻼﮐ ﮏﯾ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺯﺍ ﻞﺒﻗ ﻪﮐ ﺖﺳﺎﻨﻌﻣ ﻥﺍﺪﺑ ﻦﯾﺍ

ﻝﺎﺜﻣ

 //You cannot use the class yet.
//myCar = new Car("Ford") will raise an error.
class Car {	  constructor(brand) {
    this.carname = brand;	  }
}
//Now you can use the class:
const myCar = new Car("Ford")

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

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Classes are not Hoisted</h1>
<p>You will get an error if you try to use a class before it is declared.</p>

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

<script>
//You cannot use the class yet.
//myCar = new Car("Ford") will raise an error.

class Car {
  constructor(brand) {
    this.carname = brand;
  }
}

//Now you can use the class:
const myCar = new Car("Ford");
document.getElementById("demo").innerHTML = myCar.carname;

</script>

</body>
</html>

ﻪﺟﻮﺗ: ﻥﻼﻋﺍ ﺮﯾﺎﺳ ﯼﺍﺮﺑﺩﺮﮐ ﺪﯿﻫﺍﻮﺨﻧ ﺖﻓﺎﯾﺭﺩ ﺩﺪﻋ ﮏﯾ ،ﻊﺑﺍﻮﺗ ﺪﻨﻧﺎﻣ ،ﺎﻫ