Created
May 21, 2018 12:23
-
-
Save zhangkn/1e2fe7e56941a6606b216f9dd4b578d0 to your computer and use it in GitHub Desktop.
object 是一种无序的键值对。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var o = {} //生成一个新的空对象 | |
//生成一个新的非空对象 | |
o = { | |
'string' : 1, //object 的 key 可以是字符串 | |
const_var : 2, //object 的 key 也可以是符合变量定义规则的标识符 | |
func : {}, //object 的 value 可以是任何类型 | |
}; | |
//对象属性的读操作 | |
console.log(1 === o['string']); | |
console.log(2 === o.const_var); | |
//对象属性的写操作 | |
o['string']++; | |
o['string'] += 10; | |
o.const_var++; | |
o.const_var += 10; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment