初学JavaScript须知道的七件事
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了初学JavaScript须知道的七件事相关的知识,希望对你有一定的参考价值。
1.1、缩略标记
//定义对象 //var car = new Object(); //car.colour = ‘red‘; //car.wheels = 4; //car.hubcaps = ‘spinning‘; //car.age = 4; //上述代码的简洁写法: var car = { colour: ‘red‘, wheels: 4, hubcaps: ‘spinning‘, age: 4 } //定义数组 var testArr = new Array(‘str1‘, ‘str2‘, ‘str3‘, ‘str4‘); //上述代码的简洁写法: var testArr = [‘str1‘, ‘str2‘, ‘str3‘, ‘str4‘]; //关联数组 var car = new Array(); car[‘colour‘] = ‘red‘; car[‘wheels‘] = 4; car[‘hubcaps‘] = ‘spinning‘; car[‘age‘] = 4;
//三重标记法
var direction;
if(x<200){ direction=1;}else{direction=-1}
//用三重标记法可写为
var direction=x<200?1:-1;
1.2、JSON数据格式
JSON是javascript Object Notion的缩写
//描述乐队 var band = { "name": "The Red Hot Chili Peppers", "members": [ { "name": "zhangsan", "role": "lead vocals" }, { "name": "lisi", "role": "bass guitar,trumpet,backing vocals" } ], "year":"2009" }
JSON-P 跨域应用:http://www.cnblogs.com/chopper/archive/2012/03/24/2403945.html
以上是关于初学JavaScript须知道的七件事的主要内容,如果未能解决你的问题,请参考以下文章