当前位置:Gxlcms > JavaScript > javascriptobjectoriented面向对象编程初步_基础知识

javascriptobjectoriented面向对象编程初步_基础知识

时间:2021-07-01 10:21:17 帮助过:30人阅读

用 new Object() 来创建对象
在javascript里有几种创建对象的方法,在不同的场合可用不同的方法.最简单的就是用 new 操作符,例如:
代码如下:

How do I loop through properties in an object?
You need to use a for/in loop.
我们可以通过for in循环来遍历对象的属性。




The important thing to notice is that in the object syntax the property is an identifier, whereas in the array syntax, it's a string. The obvious benefits of using an array syntax to access an object is because of the literal data type, you can easily concat strings and play around with them to access an object. For this to work with the standard syntax, an eval() would need to be used.
应该值得注意的是对象的属性只是一个标识字符,尽管在一个数组里是一个字符串,因为是一个literal的数据类型,所以有利于使用数组的方式的操作一个对象。你也可以很容易的存取一个对象在标准的语句中。这个时候eval()函数可能用得到。