ﺪﻧﺮﺑ ﯽﻣ ﺙﺭﺍ ﻪﺑ ﺍﺭ ﺎﻫﺪﺘﻣ ﻭ ﺹﺍﻮﺧ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ءﺎﯿﺷﺍ ﻡﺎﻤﺗ
:ﻢﯿﺘﻓﺮﮔ ﺩﺎﯾ ﺍﺭ ﯽﺷ ﻩﺪﻧﺯﺎﺳ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻩﻮﺤﻧ ﻞﺒﻗ ﻞﺼﻓ ﺭﺩ
function Person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
}
const myFather = new Person("John", "Doe", 50, "blue");
const myMother = new Person("Sally", "Rally", 48, "green");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Objects</h2>
<p>Using an object constructor:</p>
<p id="demo"></p>
<script>
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
const myFather = new Person("John", "Doe", 50, "blue");
const myMother = new Person("Sally", "Rally", 48, "green");
document.getElementById("demo").innerHTML =
"My father is " + myFather.age + ". My mother is " + myMother.age;
</script>
</body>
</html>
:ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﺪﯾﺎﺒﻧ ﺩﻮﺟﻮﻣ ﯽﺷ ﻩﺪﻧﺯﺎﺳ ﻪﺑ ﺍﺭ ﺪﯾﺪﺟ ﯽﮔﮋﯾﻭ ﮏﯾ ﺪﯿﻧﺍﻮﺗﯽﻤﻧ
Person.nationality = "English";
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Objects</h2>
<p>You cannot add a new property to a constructor function.</p>
<p id="demo"></p>
<script>
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
Person.nationality = "English";
const myFather = new Person("John", "Doe", 50, "blue");
const myMother = new Person("Sally", "Rally", 48, "green");
document.getElementById("demo").innerHTML =
"The nationality of my father is " + myFather.nationality;
</script>
</body>
</html>
ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﻥﺁ ﻪﺑ ﺍﺭ ﻥﺁ ﺪﯾﺎﺑ ،ﻩﺪﻧﺯﺎﺳ ﻪﺑ ﺪﯾﺪﺟ ﯽﮔﮋﯾﻭ ﮏﯾ ﻥﺩﻭﺰﻓﺍ ﯼﺍﺮﺑ
function Person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
this.nationality = "English";
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Objects</h1>
<p>Using an object constructor:</p>
<p id="demo"></p>
<script>
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
this.nationality = "English";
}
const myFather = new Person("John", "Doe", 50, "blue");
const myMother = new Person("Sally", "Rally", 48, "green");
document.getElementById("demo").innerHTML =
"The nationality of my father is " + myFather.nationality + ". The nationality of my mother is " + myMother.nationality;
</script>
</body>
</html>
:ﺪﻧﺮﺑ ﯽﻣ ﺙﺭﺍ ﻪﺑ ﻪﯿﻟﻭﺍ ﻪﻧﻮﻤﻧ ﮏﯾ ﺯﺍ ﺍﺭ ﺎﻫﺪﺘﻣ ﻭ ﺹﺍﻮﺧ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ءﺎﯿﺷﺍ ﻡﺎﻤﺗ
ﺦﯾﺭﺎﺗ
ﺯﺍ ءﺎﯿﺷﺍ Date.protot
ﺪﻧﺮﺑ ﯽﻣ ﺙﺭﺍ ﻪﺑ Array.prototype
ﺯﺍ ﻪﯾﺍﺭﺁ<"code
ﺪﻧﺮﺑ ﯽﻣ ﺙﺭﺍ ﻪﺑ Person.prototype
ﺯﺍ Object.prototype
ﺩﺭﺍﺩ ﺭﺍﺮﻗ ﻪﯿﻟﻭﺍ ﻪﻧﻮﻤﻧ ﺖﺛﺍﺭﻭ ﻩﺮﯿﺠﻧﺯ
.ﺪﻧﺮﺑ ﯽﻣ ﺙﺭﺍ ﻪﺑ Object.prototype
ﺯﺍ ءﺎﯿﺷﺍ ﺺﺨﺷ
.ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﺹﺎﺧ ﻉﻮﻧ ﮏﯾ ﺯﺍ ﺩﻮﺟﻮﻣ ءﺎﯿﺷﺍ ﻡﺎﻤﺗ ﻪﺑ ﺍﺭ ﯼﺪﯾﺪﺟ (ﯼﺎﻫﺪﺘﻣ ﺎﯾ) ﺎﻫ ﯽﮔﮋﯾﻭ ﺪﯿﻫﺍﻮﺧ ﯽﻣ
ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﯽﺷ ﮏﯾ ﻪﺑ ﺍﺭ ﯼﺪﯾﺪﺟ (ﯼﺎﻫﺪﺘﻣ ﺎﯾ) ﺎﻫ ﯽﮔﮋﯾﻭ ﺪﯿﻫﺍﻮﺧ ﯽﻣ ﺕﺎﻗﻭﺍ ﯽﻫﺎﮔ
.ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﯽﺷ ﻪﺑ ﺍﺭ ﯼﺪﯾﺪﺟ ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﺪﻫﺩ ﯽﻣ ﻥﺎﮑﻣﺍ ﺎﻤﺷ ﻪﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﭗﯾﺎﺗﻮﺗﻭﺮ
function Person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
}
Person.prototype.nationality = "English";
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Objects</h2>
<p>The prototype property allows you to add new methods to objects constructors:</p>
<p id="demo"></p>
<script>
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
Person.prototype.nationality = "English";
const myFather = new Person("John", "Doe", 50, "blue");
document.getElementById("demo").innerHTML =
"The nationality of my father is " + myFather.nationality;
</script>
</body>
</html>
.ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﺎﯿﺷﺍ ﻪﺑ ﺍﺭ ﯼﺪﯾﺪﺟ ﯼﺎﻫ ﺵﻭﺭ ﺪﻫﺩ ﯽﻣ ﻥﺎﮑﻣﺍ ﺎﻤﺷ ﻪﺑ ﻦﯿﻨﭽﻤﻫ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﺪﯿﻫﺪﻧ ﺮﯿﯿﻐﺗ ﺍﺭ ﻪﯿﻟﻭﺍ ﯼﺎﻫ ﻪﻧﻮﻤﻧ ﺰﮔﺮﻫ .ﺪﯿﻫﺩ ﺮﯿﯿﻐﺗ ﺍﺭ ﺩﻮﺧ ﺩﻮﺧ ﻪﯿﻟﻭﺍ ﯼﺎﻫ ﻝﺎﺜﻣ
function Person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
}
Person.prototype.name = function() {
return this.firstName + " " + this.lastName;
};
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Objects</h2>
<p id="demo"></p>
<script>
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
Person.prototype.name = function() {
return this.firstName + " " + this.lastName
};
const myFather = new Person("John", "Doe", 50, "blue");
document.getElementById("demo").innerHTML =
"My father is " + myFather.name();
</script>
</body>
</html>