JavaScript quotes

An object is very similar to an array but with the difference that you define the keys yourself. You're not limited to using only numeric indexes but can use friendlier keys, such as first_name, age, and so on.
Let's take a look at a simple object and examine its parts:
var hero = {
breed: 'Turtle',
occupation: 'Ninja'
};
You can see that:
The name of the variable that contains the object is hero
Instead of [ and ] which you use to define an array, you use { and }
for objects
You separate the elements (called properties) contained in the object
with commas
The key/value pairs are divided by colons, as key: value
The keys (names of the properties) can optionally be placed in quotation marks.
For example these are all the same:
var o = {prop: 1};
var o = {"prop": 1};
var o = {'prop': 1};
It's recommended that you don't quote the names of the properties (it is also less typing!), but there are some cases when you have must use quotes:
If the property name is one of the reserved words in JavaScript (see Appendix A)
If it contains spaces or special characters (anything other than letters, numbers, and the underscore character)
If it starts with a number

 

 

Accessing Object's Properties
There are two ways to access a property of an object:
Using square bracket notation, for example hero['occupation']
Using the dot notation, for example hero.occupation

属性也可能是函数

时间: 2024-09-04 07:40:15

JavaScript quotes的相关文章

利用PHP+JavaScript打造AJAX搜索窗

一. 引言 Web世界中一项广为使用的功能就是搜索.随着Web技术的日益发展,为了更好地满足客户的需求,常规搜索引擎开始对更多的非常规方式"敞开了大门".在这方面,Yahoo!率先提供出其Y!Q服务.这个新的服务能够使你搜索任何web页面,前提是该页面的作者必须包括在他们的web页面中.是服务技术实现了把相关的搜索结果呈现到读者眼前,从而向读者展示更多的信息而不必离开他们的当前页面. Yahoo!的Y!Q服务的确是一个伟大的想法,但是它的出现也受到了一些批评.原因何在?首先,它要求客户

使用PHP JavaScript制作AJAX搜索引擎

一. 引言 Web世界中一项广为使用的功能就是搜索.随着Web技术的日益发展,为了更好地满足客户的需求,常规搜索引擎开始对更多的非常规方式"敞开了大门".在这方面,Yahoo!率先提供出其Y!Q服务.这个新的服务能够使你搜索任何web页面,前提是该页面的作者必须包括在他们的web页面中.是服务技术实现了把相关的搜索结果呈现到读者眼前,从而向读者展示更多的信息而不必离开他们的当前页面. Yahoo!的Y!Q服务的确是一个伟大的想法,但是它的出现也受到了一些批评.原因何在?首先,它要求客户

JavaScript代码优化新工具UglifyJS

jQuery 1.5 发布的时候 john resig 大神说所用的代码优化程序从Google Closure切换到UglifyJS,新工具的压缩效果非常令人满意. UglifyJS 是一个服务端node.js的压缩程序.我测试了一下压缩率确实比较高. 所以值得写篇文章推荐下. 你也可以尝试一下在线版的Uglifyjs: http://sweet.fengyin.name/ 如果你对 uglifyjs 有兴趣可以按照以下安装方式进行安装. 1. 安装 node.js 环境 2. 进入 https

用JavaScript实现一些随机事件

javascript|随机 1.随机广告 <SCRIPT LANGUAGE="JavaScript"> <!-- Begin var how_many_ads = 3; var now = new Date() var sec = now.getSeconds() var ad = sec % how_many_ads; ad +=1; if (ad==1) { txt="The World's Largest Online Bookstore, Amazo

JavaScript中字面量与函数的基本使用知识_基础知识

JavaScript 字面量 在编程语言中,一个字面量是一个常量,如 3.14. 数字(Number)字面量 可以是整数或者是小数,或者是科学计数(e). 3.14 1001 123e5 字符串(String)字面量 可以使用单引号或双引号 be written with double or single quotes: "John Doe" 'John Doe' 表达式字面量 用于计算: 5 + 6 5 * 10 数组(Array)字面量 定义一个数组: [40, 100, 1, 5

如何正确使用javascript 来进行我们的程序开发_javascript技巧

今天在github 上面找到了一个关于如何正确使用javascript 来进行我们的程序开发.我就恬不知耻的来了个原创啊..坑爹啊.拿来和大家分享一下吧. A mostly reasonable approach to Javascript. Types //类型 Objects //对象 Arrays //数组 Strings //字符串 Functions //函数 Properties //属性 Variables //变量 Hoisting //变量提升 Conditional Expr

JavaScript实现带箭头标识的多级下拉菜单效果_javascript技巧

本文实例讲述了JavaScript实现带箭头标识的多级下拉菜单效果.分享给大家供大家参考.具体如下: 这是一个支持多级显示的JS菜单,鼠标移向带有小三角的菜单项,可下拉出二级子菜单项,在该主菜单的上方会显示标记,指引当前的位置,本菜单代码使用了一个JS类,可根据代码地址自行下载,这个菜单未在网上测试,用在自己的网站里可能要修改代码. 运行效果截图如下: 在线演示地址如下: http://demo.jb51.net/js/2015/js-focus-m-select-menu-nav-codes/

javascript asp教程添加和修改_ASP基础

The Connection Execute(): If you want to retrieve data from a database then you have no choice but to use a Recordset. However, for the purposes of adding, updating, and deleting data you don't necessarily have to have a Recordset. It's up to you. Fo

JavaScript mapreduce工作原理简析_基础知识

谷歌在2003到2006年间连续发表了三篇非常有影响力的文章,分别是2003年在SOSP上发布的GFS,2004年在OSDI上发布的MapReduce,以及2006年在OSDI上发布的BigTable.GFS是文件系统相关的,其对后来的分布式文件系统设计具有指导意义:MapReduce是一种并行计算的编程模型,用于作业调度:BigTable是一个用于管理结构化数据的分布式存储系统,构建在GFS.Chubby.SSTable等Google技术之上.相当多的Google应用使用了这三种技术,比如Go