[英]What is the correct term for a JSON object with methods?
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?
即使具有功能绑定,它只是一个JSON对象吗? In the example I gave, could I call fullName a method?
在我给出的示例中,可以将fullName称为方法吗?
You can find the difference in JSON & Object literal here . 您可以在此处找到JSON&Object文字的区别。
person is an object literal.
person是对象文字。
Properties ( firstName, lastName, id ) is like a noun which refers the person details.
属性( firstName,lastName,id )就像一个名词,表示人的详细信息。
Method ( fullName ) is like a verb that describes an action.
方法( fullName )类似于描述动作的动词。
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. 它具有属性
person.firstName
, person.lastName
, person.id
和方法person.fullName()
,它们返回人员的全名,其中包括人员firstName
和lastName
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.