+ 1
trouble learning javascript because of the brackets and objects help.
help mw its too confusing
1 Answer
+ 1
An Example oft an Object:
var student1 ={ //defining an JS Object
name:"Christoph", //ALWAYS use comma!!
age:22, //22 is a integer and not a string,
so we don't need to put the value
in quotation marks.
gender:"male" //no need to put a comma at the
end of the name:value pair,
because it is the last pair in the
JavaScript object.
}
Now that was an example ofof an simple javascript object.
If you want to create a new student
we need following:
-An student constructor method
- And an expression to create a new student object
This coukd look like following script:
//Expression for creating a new student object
var student2 = new student("John",23,"male");
//The constructor method
//Remember, that "this" is NOT a variable. It
just represents the current object.
function student(name,age,gender){
this.name = name;
this.age = age;
this.gender = gender;
}
So that's it for now. If there's any question or I forgot something, feel free to ask me anything :]
Hope it was a bit helpful!