If I have the following code:
var person = {
firstName: "John",
lastName : "Doe",
id : 5566,
fullName : function() {
return this.firstName + " " + this.lastName;
}
};
What is it called? Is it just a JSON object, even though it has a function binding? In the example I gave, could I call fullName a method?
You can find the difference in JSON & Object literal here .
person is an object literal.
Properties ( firstName, lastName, id ) is like a noun which refers the person details.
Method ( fullName ) is like a verb that describes an action.
var person = { firstName: "John", lastName : "Doe", id : 5566, fullName : function() { return this.firstName + " " + this.lastName; } }; console.log("FirstName :", person.firstName); console.log("Full Name :", person.fullName());
Here, person is an object. It has a property person.firstName
, person.lastName
, person.id
and method person.fullName()
that return full name of the person which include the person firstName
& lastName
property.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.