码迷,mamicode.com
首页 > 编程语言 > 详细

初学JavaScript须知道的七件事

时间:2016-10-12 00:19:39      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

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须知道的七件事

标签:

原文地址:http://www.cnblogs.com/vakeynb/p/5951240.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!