In JavaScript, isn't Object Literal Notation just another name for a dictionary? - Stack Overflow

Isn't a JavaScript "Object" just a dictionary? Why is there a fancy name for Object Lite

Isn't a JavaScript "Object" just a dictionary? Why is there a fancy name for Object Literal Notation? And for JavaScript Object Literal Notation, you can only refer to the object's property's value with Object.property and not Object[property] (as you would do in Python)?

Isn't a JavaScript "Object" just a dictionary? Why is there a fancy name for Object Literal Notation? And for JavaScript Object Literal Notation, you can only refer to the object's property's value with Object.property and not Object[property] (as you would do in Python)?

Share Improve this question asked Aug 21, 2012 at 23:18 bigpotatobigpotato 27.6k60 gold badges194 silver badges360 bronze badges 4
  • 8 Object[property] is valid in Javascript. – Ivan Commented Aug 21, 2012 at 23:20
  • If property is strictly numeric or includes spaces or other characters or is the result of an expression, you must use Object[property] – Michael Berkowski Commented Aug 21, 2012 at 23:21
  • Everything in JS is a dictionary, but i guess i always thought of object-literal notation as a way to define objects in a more readable way that feels like classes. – pdizz Commented Aug 21, 2012 at 23:25
  • 3 @MichaelBerkowski: A Python dict doesn't have to just contain scalars. The values can be anything, including functions and "I am z"s. – voithos Commented Aug 21, 2012 at 23:27
Add a ment  | 

1 Answer 1

Reset to default 8

Javascript's "Object Literal Notation" is simply the syntax that javascript accepts for a statically declared data structure. While a javascript object can be used similarly to what is called a dictionary in other languages, "Object Literal Notation" is just a static declaration syntax. It would typically look something like this:

var myObject = {
    name: "Peter Foti",
    'course': 'JavaScript',
    grade: 'A',
    level: 3
};

The term "Object Literal Notation" does not refer to all possible ways that you can address an object with javscript code. You don't use either the Object.property or Object[property] syntax to define a property in a static object declaration except as the value part of a declaration where the Object is some other object.

This article has a good reference on the Object Literal syntax under the heading Basic Syntax.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742152546a4391846.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信