function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
.ﺩﻮﺷ ﯽﻣ ﻪﺘﻓﺮﮔ ﺮﻈﻧ ﺭﺩ ﯽﺑﻮﺧ ﻞﻤﻋ ﮒﺭﺰﺑ ﻝﻭﺍ ﻑﺮﺣ ﺎﺑ ﻩﺪﻧﺯﺎﺳ ﻊﺑﺍﻮﺗ ﯼﺭﺍﺬﮕﻣﺎﻧ
.ﺩﺭﺍﺪﻧ ﯼﺭﺍﺪﻘﻣ ﻦﯾﺍ<"code class="w3-codespan> ﻩﺪﻧﺯﺎﺳ ﻊﺑﺎﺗ ﮏﯾ ﺭﺩ
ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻦﯾﺍ ﺵﺯﻮﻣﺁ
.ﺪﻨﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﺪﺣﺍﻭ ءﺎﯿﺷﺍ ﻂﻘﻓ ﺎﻬﻧﺁ .ﺖﺳﺍ ﺩﻭﺪﺤﻣ ﻞﺒﻗ ﯼﺎﻫ ﻞﺼﻓ ﯼﺎﻫ ﻝﺎﺜﻣ
.ﻢﯾﺭﺍﺩ ﺯﺎﯿﻧ "ﺡﺮﻃ" ﮏﯾ ﻪﺑ ،ﻉﻮﻧ ﮏﯾ ﺯﺍ ءﺎﯿﺷﺍ ﺯﺍ ﯼﺭﺎﯿﺴﺑ ﺩﺎﺠﯾﺍ ﯼﺍﺮﺑ ﺕﺎﻗﻭﺍ
.ﺖﺳﺍ ﯽﺷ ﻩﺪﻧﺯﺎﺳ ﺩﺮﮑﻠﻤﻋ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ،"ﯽﺷ ﻉﻮﻧ" ﮏﯾ ﺩﺎﺠﯾﺍ ﻩﺍﺭ
.ﺖﺳﺍ ﯽﺷ ﻩﺪﻧﺯﺎﺳ ﻊﺑﺎﺗ ﮏﯾ function Person()
،ﻻﺎﺑ ﻝﺎﺜﻣ ﺭ
:ﺪﻧﻮﺷ ﯽﻣ ﺩﺎﺠﯾﺍ new
ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺎﺑ ﻩﺪﻧﺯﺎﺳ ﻊﺑﺎﺗ ﯽﻧﺍﻮﺧﺍﺮ
const myFather = new Person("John", "Doe", 50, "blue");
const myMother = new Person("Sally", "Rally", 48, "green");
.ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﺷ ﮏﯾ ﻪﺑ this
ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ،ﺖﭙﯾﺮﮑﺳﺍ
ﻡﺍﺪﮐ (ﯽﻧﺍﻮﺧﺍﺮﻓ ﺎﯾ ﻩﺩﺎﻔﺘﺳﺍ) ﯽﻧﺍﻮﺧﺍﺮﻓ ﻩﻮﺤﻧ ﻪﺑ ﯽﮕﺘﺴﺑ ﯽﺷ :ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﻔﻠﺘﺨﻣ ءﺎﯿﺷﺍ ﻪﺑ ﻥﺁ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﻩﻮﺤﻧ ﻪﺑ ﻪﺘﺴﺑ .ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﺷ ﻪﺑ .ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﻧﺎﻬﺟ ءﯽﺷ ﻪﺑ .ﺩﺭﺍﺩ ﻩﺭﺎﺷﺍ ﯽﻧﺎﻬﺟ ءﯽﺷ ﻪﺑ .ﺖﺳﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﻦﯾﺍ ﺵﺯﻮﻣﺁthis
ﻦﯾﺍ<"code class="w3-codespan> ،ﯽﺷ ﺵﻭﺭ ﮏﯾ ﺭﺩ
ﻦﯾﺍ<"code class="w3-codespan> ،ﯽﯾﺎﻬﻨﺗ ﻪﺑ
ﻦﯾﺍ<"code class="w3-codespan> ،ﻊﺑﺎﺗ ﮏﯾ ﺭﺩ
ﻩﺪﺸﻧ ﻒﯾﺮﻌﺗ<"code>
ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﻪﺟﻮﺗ
ﻦﯾﺍ
ﺭﺍﺪﻘﻣ ﺪﯿﻧﺍﻮﺗ ﯽﻤﻧ ﺎﻤﺷ .ﺖﺳﺍ ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﮏﯾ .ﺖﺴﯿﻧ ﺮﯿ :ﺪﯿﻨﯿﺒﺑ ﻦﯿﻨﭽﻤﻫ
:ﺖﺳﺍ ﻥﺎﺳﺁ ﺩﻮﺟﻮﻣ ﯽﺷ ﮏﯾ ﻪﺑ ﺪﯾﺪﺟ ﯽﮔﮋﯾﻭ ﮏﯾ ﻥﺩﻭﺰﻓﺍ
myFather.nationality = "English";
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Object Constructors</h2>
<p id="demo"></p>
<script>
// Constructor function for Person objects
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
// Create 2 Person objects
const myFather = new Person("John", "Doe", 50, "blue");
const myMother = new Person("Sally", "Rally", 48, "green");
// Add nationality to first object
myFather.nationality = "English";
// Display nationality
document.getElementById("demo").innerHTML =
"My father is " + myFather.nationality;
</script>
</body>
</html>
.(ءﺎﯿﺷﺍ ﯼﺮﮕﯾﺩ ﺺﺨﺷ ﭻﯿﻫ ﻪﺑ ﻪﻧ) ﻡﺭﺩﺎﻣ ﻪﺑ ﻪﻧ .ﺪﺷ ﺪﻫﺍﻮﺧ ﻪﻓﺎﺿﺍ myFather ﻪﺑ ﯽﯾﺍﺭﺍﺩ
:ﺖﺳﺍ ﻥﺎﺳﺁ ﺩﻮﺟﻮﻣ ﯽﺷ ﮏﯾ ﻪﺑ ﺪﯾﺪﺟ ﺵﻭﺭ ﮏﯾ ﻥﺩﻭﺰﻓﺍ
myFather.name = function () {
return this.firstName + " " + this.lastName;
};
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Object Constructors</h2>
<p id="demo"></p>
<script>
// Constructor function for Person objects
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
// Create 2 Person objects
const myFather = new Person("John", "Doe", 50, "blue");
const myMother = new Person("Sally", "Rally", 48, "green");
// Add a name method to first object
myFather.name = function() {
return this.firstName + " " + this.lastName;
};
// Display full name
document.getElementById("demo").innerHTML =
"My father is " + myFather.name();
</script>
</body>
</html>
.(ءﺎﯿﺷﺍ ﯼﺮﮕﯾﺩ ﺺﺨﺷ ﭻﯿﻫ ﻪﺑ ﻪﻧ) ﻡﺭﺩﺎﻣ ﻪﺑ ﻪﻧ .ﺪﺷ ﺪﻫﺍﻮﺧ ﻪﻓﺎﺿﺍ myFather ﻪﺑ ﺪﺘﻣ ﻦﯾﺍ
ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﺩﻮﺧ ﺵﻭﺭ ﻥﺎﻤﻫ ﻪﺑ ءﯽﺷ ﻩﺪﻧﺯﺎﺳ ﮏﯾ ﻪﺑ ﺍﺭ ﺪﯾﺪﺟ ﯽﮔﮋﯾﻭ ﮏﯾ ﺪﯿﻧﺍﻮﺗ ﯽﻤﻧ ﺎﻤﺷ
Person.nationality = "English";
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Object Constructors</h2>
<p>You cannot add a new property to a constructor function.</p>
<p id="demo"></p>
<script>
// Constructor function for Person objects
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
// You can NOT add a new property to a constructor function
Person.nationality = "English";
// Create 2 Person objects
const myFather = new Person("John", "Doe", 50, "blue");
const myMother = new Person("Sally", "Rally", 48, "green");
// Display nationality
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>
<h2>JavaScript Object Constructors</h2>
<p id="demo"></p>
<script>
// Constructor function for Person objects
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
this.nationality = "English";
}
// Create 2 Person objects
const myFather = new Person("John", "Doe", 50, "blue");
const myMother = new Person("Sally", "Rally", 48, "green");
// Display nationality
document.getElementById("demo").innerHTML =
"My father is " + myFather.nationality + ". My mother is " + myMother.nationality;
</script>
</body>
</html>
.ﺪﻨﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺽﺮﻓ ﺶﯿﭘ ﺮﯾﺩﺎﻘﻣ ﺪﻨﻧﺍﻮﺗ ﯽﻣ ﯽﺷ ﯼﺎﻫ ﯽﮔﮋﯾﻭ ﺐﯿﺗﺮﺗ ﻦﯾﺍ ﻪﺑ
:ﺪﻨﮐ ﻒﯾﺮﻌﺗ ﺍﺭ ﺎﻫﺪﺘﻣ ﺪﻧﺍﻮﺗ ﯽﻣ ﻦﯿﻨﭽﻤﻫ ﺎﻤﺷ ﻩﺪﻧﺯﺎﺳ ﻊﺑﺎﺗ
function Person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
this.name = function() {
return this.firstName + " " + this.lastName;
};
}
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Object Constructors</h2>
<p id="demo"></p>
<script>
// Constructor function for Person objects
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
this.name = function() {
return this.firstName + " " + this.lastName
};
}
// Create a Person object
const myFather = new Person("John", "Doe", 50, "blue");
// Display full name
document.getElementById("demo").innerHTML =
"My father is " + myFather.name();
</script>
</body>
</html>
ﺪﯿﻨﮐ ﻪﻓﺎﺿﺍ ﯽﺷ ﻩﺪﻧﺯﺎﺳ ﻪﺑ ﺪﯾﺪﺟ ﺪﺘﻣ ﮏﯾ ،ﺪﯿﻨﮐ ﯽﻣ ﻪﻓﺎﺿﺍ ﺍﺭ a ﻪﮐ ﯽﺷﻭﺭ ﻥﺎﻤﻫ ﻪﺑ ﺪﯿﻧﺍﻮﺗ ﯽﻤﻧ ﺎﻤ
ﺩﻮﺷ ﻡﺎﺠﻧﺍ ﻞﺧﺍﺩ ﺭﺩ ﺪﯾﺎﺑ ﯽﺷ ﻩﺪﻧﺯﺎﺳ ﮏﯾ ﻪﺑ ﺎﻫﺪﺘﻣ ﻥﺩﻭﺰﻓﺍ
function Person(firstName, lastName, age, eyeColor) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.eyeColor = eyeColor;
this.changeName = function (name) {
this.lastName = name;
};
}
ﺪﻫﺩ ﯽﻣ ﺹﺎﺼﺘﺧﺍ ﺺﺨﺷ ﻪﺑ ﺍﺭ name ﺭﺍﺪﻘﻣ()changeName ﻊﺑﺎﺗ
myMother.changeName("Doe");
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Object Constructors</h2>
<p id="demo"></p>
<script>
// Constructor function for Person objects
function Person(firstName,lastName,age,eyeColor) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.eyeColor = eyeColor;
this.changeName = function (name) {
this.lastName = name;
}
}
// Create a Person object
const myMother = new Person("Sally","Rally",48,"green");
// Change last name
myMother.changeName("Doe");
// Display last name
document.getElementById("demo").innerHTML =
"My mother's last name is " + myMother.lastName;
</script>
</body>
</html>
ﺪﯿﺘﺴﻫ ﯽﺴﮐ ﻪﭼ ﺎﻤﺷ ﻪﮐ ﺪﻧﺍﺩ ﯽﻣ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
:ﺩﺭﺍﺩ ﯽﻣﻮﺑ ءﺎﯿﺷﺍ ﯼﺍﺮﺑ ﯽﻠﺧﺍﺩ ﯼﺎﻫ ﻩﺪﻧﺯﺎﺳ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
new String() // A new String object
new Number() // A new Number object
new Boolean() // A new Boolean object
new Object() // A new Object object
new Array() // A new Array object
new RegExp() // A new RegExp object
new Function() // A new Function object
new Date() // A new Date object
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Object Constructors</h2>
<p id="demo"></p>
<script>
const x1 = new String(); // A new String object
const x2 = new Number(); // A new Number object
const x3 = new Boolean(); // A new Boolean object
const x4 = new Object(); // A new Object object
const x5 = new Array(); // A new Array object
const x6 = new RegExp(); // A new RegExp object
const x7 = new Function(); // A new Function object
const x8 = new Date(); // A new Date object
// Display the type of all objects
document.getElementById("demo").innerHTML =
"x1: " + typeof x1 + "<br>" +
"x2: " + typeof x2 + "<br>" +
"x3: " + typeof x3 + "<br>" +
"x4: " + typeof x4 + "<br>" +
"x5: " + typeof x5 + "<br>" +
"x6: " + typeof x6 + "<br>" +
"x7: " + typeof x7 + "<br>" +
"x8: " + typeof x8 + "<br>";
</script>
<p>There is no need to use new String(), new Number(), new Boolean(), new Array(), and new RegExp()</p>
<p>Use literals instead like: myArray = []</p>
</body>
</html>
ﺩﺮﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻥﺁ ﺭﺩ ﻥﺍﻮﺗ ﯽﻤﻧ ﺍﺭ ﺪﯾﺪﺟ<"code class="w3-codespan> ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ .ﺖﺳﺍ ﯼ
ﺖﺳﺍ ﻪﯿﻟﻭﺍ ءﯽﺷ ﯼﺎﻫ ﻪﺨﺴﻧ ﯼﺍﺭﺍﺩ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ،ﺪﯿﻨﯿﺑ ﯽﻣ ﻻﺎﺑ ﺭﺩ ﻪﮐ ﺭﻮﻄﻧﺎﻤﻫ
.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ""
ﯼﺍ ﻪﺘﺷﺭ ﺕﺎﻤﻠﮐ ﺯﺍ 50
ﯽﻌﻗﺍﻭ ﺩﺍﺪﻋﺍ ﺯﺍ true/false
ﯽﻟﻮﺑ ﻆﻔﻟ ﺯﺍ {}
ﺊﺷ ﯼﺎﻫ ﻩﮊﺍﻭ ﺯﺍ []
ﻪﯾﺍﺭﺁ ﺕﺎﻤﻠﮐ ﺯﺍ /()/
ﯽﻌﻗﺍﻭ ﯼﺎﻫﻮﮕﻟﺍ ﺯﺍ () {}
ﻊﺑﺎﺗ ﺕﺍﺭﺎﺒﻋ ﺯﺍ ﻝﺎﺜﻣ
let x1 = ""; // new primitive string
let x2 = 0; // new primitive number
let x3 = false; // new primitive boolean
const x4 = {}; // new Object object
const x5 = []; // new Array object
const x6 = /()/ // new RegExp object
const x7 = function(){}; // new function
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
let x1 = ""; // string
let x2 = 0; // number
let x3 = false; // boolean
const x4 = {}; // Object object
const x5 = []; // Array object
const x6 = /()/; // RegExp object
const x7 = function(){}; // function
// Display the type of all
document.getElementById("demo").innerHTML =
"x1: " + typeof x1 + "<br>" +
"x2: " + typeof x2 + "<br>" +
"x3: " + typeof x3 + "<br>" +
"x4: " + typeof x4 + "<br>" +
"x5: " + typeof x5 + "<br>" +
"x6: " + typeof x6 + "<br>" +
"x7: " + typeof x7 + "<br>";
</script>
</body>
</html>
firstName="John"
:ﺪﻧﻮﺷ ﯽﻣ ﺩﺎﺠﯾﺍ ﻪﯿﻟﻭﺍ ﺕﺭﻮﺻ ﻪﺑ ﺎﻫ ﻪ
:ﺩﺮﮐ ﺩﺎﺠﯾﺍ ﺰﯿﻧ ﺎﯿﺷﺍ ﻥﺍﻮﻨﻋ ﻪﺑ new
ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺯﺍ ﻩ
ﺪﻧﻮﺷ ﺩﺎﺠﯾﺍ ﻞﺼﻓ ﺭﺩ ﯽﺷ ﻥﺍﻮﻨﻋ ﻪﺑ ﺪﯾﺎﺒﻧ ﺎﻫ ﻪﺘﺷﺭ ﺍﺮﭼ ﻪﮐ ﺪﯾﺯﻮﻣﺎﯿﺑ
x=30
:ﺪﻧﻮﺷ ﯽﻣ ﺩﺎﺠﯾﺍ ﻪﯿﻟﻭﺍ ﺕﺭﻮﺻ ﻪﺑ ﺩﺍﺪﻋﺍ ،ﻝﻮﻤﻌﻣ ﺭﻮﻃ
:ﺪﻧﻮﺷ ﺩﺎﺠﯾﺍ new
ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﺎﯿﺷﺍ ﻥﺍ
ﺪﻧﻮﺷ ﺩﺎﺠﯾﺍ ﻞﺼﻓ ﺭﺩ ﯽﺷ ﻥﺍﻮﻨﻋ ﻪﺑ ﺪﯾﺎﺒﻧ ﺩﺍﺪﻋﺍ ﺍﺮﭼ ﻪﮐ ﺪﯾﺯﻮﻣﺎﯿﺑ
=code class="w3-codespan">x> :ﺪﻧﻮﺷ ﯽﻣ ﺩﺎﺠﯾﺍ ﻪﯿﻟﻭﺍ ﺕﺭﻮﺻ ﻪﺑ ﺎﻫ ﻦﯿﻟﻮﺑ ،ﻝﻮﻤﻌﻣ ﺭﻮﻃ ﻪﺑ
:ﺪﻧﻮﺷ ﺩﺎﺠﯾﺍ new
ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ ﺯﺍ ﻩﺩﺎﻔﺘﺳﺍ ﺎﺑ ﺎﯿﺷﺍ ﻥﺍ
ﺪﻧﻮﺷ ﺩﺎﺠﯾﺍ ﻞﺼﻓ ﺭﺩ ﯽﺷ ﻥﺍﻮﻨﻋ ﻪﺑ ﺪﯾﺎﺒﻧ ﺎﻫ ﻦﯿﻟﻮﺑ ﺍﺮﭼ ﻪﮐ ﺪﯾﺯﻮﻣﺎﯿﺑ