- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › big time problem understanding object
alright now that i’ve understood how to make objects..
book = new Object();
variableName.color=”green”;
variableName.size=”10″;
What’s the point..
What to do with them?
I know i can use it to print variableName.color value onscreen, but what else….
also what are methods and what’s the use of them?
big thanks to everyone !
What’s the point.. What to do with them?
They’re particularly useful for grouping/scoping your code. But really, you might as well ask “what to do?” — objects are suitable for lots of things in javascript; it’s a pretty open-ended question.
also what are methods and what’s the use of them?
methods are functions that belong to an object.
var book = {};
book.color = "green";
book.size = 10;
book.describe = function(){
var description = "This book is " + this.color +
" and is " + this.size + " pages long.";
return description;
}
Objects have properties and methods.
Properties are just values. And methods are just functions that do something with the values.
As you can see in this example:
obj = {
firstName: "Alen",
lastName: "Mofo",
fullName: function(){
alert(this.firstName + " " + this.lastName);
}
}
obj.fullName(); //Prints "Alen Mofo"
firstName
and lastName
is a property. fullName
is a method.
Here’s a good read. http://eloquentjavascript.net/contents.html