Skip to content

Instantly share code, notes, and snippets.

@democ
Created April 1, 2014 00:44
Show Gist options
  • Save democ/9905561 to your computer and use it in GitHub Desktop.
Save democ/9905561 to your computer and use it in GitHub Desktop.

使用对象字面量(Object Literals)

对象字面量表示,就是一对大括号括起来的键值对,也就是JavaScript声明对象的方式.

  var myObject = {
    variableKey : variableValue,
    functionKey : function() {
      ...
    }
  }

比较一下下面代码声明方式,使用字面量表示,可以减少全局变量的污染,一般来说强烈建议在任何时候不要使用下面的声明方式:

  var variableName = ...;
  function name1(){

  }
  function name2(){
    
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment