# Object 和 Array 的初始化

``````[] // An empty array: no expressions inside brackets means no elements
[1+2,3+4] // A 2-element array. First element is 3, second is 7
``````

Array中的元素自身也可以是Array

``````var matrix = [[1,2,3], [4,5,6], [7,8,9]];
``````

Object的初始化表达式与Array很相似。

``````var p = { x:2.3, y:-1.2 }; // An object with 2 properties
var q = {}; // An empty object with no properties
q.x = 2.3; q.y = -1.2; // Now q has the same properties as p
var rectangle = { upperLeft: { x: 2, y: 2 },
lowerRight: { x: 4, y: 5 } };
``````

Object属性的标识符可以是字符串。而且 " 和 ' 都可以使用。

``````var side = 1;
var square = { "upperLeft": { x: p.x, y: p.y },
'lowerRight': { x: p.x + side, y: p.y + side}};
``````

# 方法定义的表达式

``````// This function returns the square of the value passed to it.
var square = function(x) { return x * x; }
``````

# 访问Property的表达式

JavaScript提供了两种访问Property的语法

``````expression . identifier
expression [ expression ]
``````

``````var o = {x:1,y:{z:3}}; // An example object
var a = [o,4,[5,6]]; // An example array that contains the object
o.x // => 1: property x of expression o
o.y.z // => 3: property z of expression o.y
o["x"] // => 1: property x of object o
a[1] // => 4: element at index 1 of expression a
a[2]["1"] // => 6: element at index 1 of expression a[2]
a[0].x // => 1: property x of expression a[0]
``````

# 方法调用的表达式

``````f(0) // f is the function expression; 0 is the argument expression.
Math.max(x,y,z) // Math.max is the function; x, y and z are the arguments.
a.sort() // a.sort is the function; there are no arguments.
``````

# 创建对象的表达式

``````new Object()
new Point(2,3)
``````

``````new Object
new Date
``````

# instanceof操作符

JavaScript提供了instanceof操作符，能够判断instanceof左右两边是否为同一对象。

``````var d = new Date(); // Create a new object with the Date() constructor
d instanceof Date; // Evaluates to true; d was created with Date()
d instanceof Object; // Evaluates to true; all objects are instances of Object
d instanceof Number; // Evaluates to false; d is not a Number object
var a = [1, 2, 3]; // Create an array with array literal syntax
a instanceof Array; // Evaluates to true; a is an array
a instanceof Object; // Evaluates to true; all arrays are objects
a instanceof RegExp; // Evaluates to false; arrays are not regular expressions
``````

# eval 表达式

JavaScript能够对JavaScript代码作解析，并生成相应的值。这个过程就是通过eval()方法完成的。

``````eval("3+2") // => 5
``````

eval()需要一个参数。

• 如果参数不是String的话，eval()会直接返回参数，而不会做任何解析。
• 当参数是一个String时，JavaScript会尝试去解析JavaScript代码，如果这段代码中碰到语法错误，JavaScript会抛出SyntaxError的错误。
• 如果没有语法问题，eval()就会执行这段代码，将最终的结果作为返回值输出。
• 如果将执行的过程中，碰到Exception,eval()将将Exception继续往外抛出给它的上层。

``````eval("function f() { return x+1; }");
``````

# typeof 操作符

``````(typeof value == "string") ? "'" + value + "'" : value
``````

``````typeof(i)
``````

typeof 的值如下：

``````x          						typeof x
undefined  							"undefined"
null         						"object"
true or false       				"boolean"
any number or NaN 					"number"
any string 							"string"
any function 						"function"
any nonfunction native object 		"object"
any host object 					An implementation-defined string, but not “undefined”,“boolean”, “number”, or “string”.
``````

instanceof 操作符可以区分不同对象，如 a instanceof Date. 而typeof无法区分具体的对象。

# delete 操作符

delete操作符可以从Objects删除Object的Property,也可以从arrays删除array item。

``````var o = { x: 1, y: 2}; // Start with an object
delete o.x; // Delete one of its properties
"x" in o // => false: the property does not exist anymore

var a = [1,2,3]; // Start with an array
delete a[2]; // Delete the last element of the array
a.length // => 2: array only has two elements now
``````

# void 操作符

void操作符的格式如下：

``````javascript:void(expression);
javascript:void expression;
``````

``````<a href="javascript:void window.open();">Open New Window</a>
``````

6/3/2014 5:02:45 PM

05/22
0
0

thinkyoung
2014/09/23
0
0
JAVASCRIPT_a href=#与 a href=javascript:void(0) 的区别

<a href="#"> 点击链接后，页面会向上滚到页首，# 默认锚点为 #TOP <a href="javascript:void(0)" onClick="window.open()"> 点击链接后，页面不动，只打开链接 <a href="#" onclick="javas......

2014/04/05
131
0

FEWY
2017/07/10
0
0

yeyan1996
07/18
0
0

OSChina 周六乱弹 —— 早上儿子问我他是怎么来的

Osc乱弹歌单（2019）请戳（这里） 【今日歌曲】 @凉小生 ：#今日歌曲推荐# 少点戾气，愿你和这个世界温柔以待。中岛美嘉的单曲《僕が死のうと思ったのは (曾经我也想过一了百了)》 《僕が死の...

2.1K
14
Excption与Error包结构，OOM 你遇到过哪些情况，SOF 你遇到过哪些情况

Throwable 是 Java 中所有错误与异常的超类，Throwable 包含两个子类，Error 与 Exception 。用于指示发生了异常情况。 Java 抛出的 Throwable 可以分成三种类型。 被检查异常（checked Exc...

Garphy

38
0

FAT_mt

40
0

61
0
tabel 中含有复选框的列 数据理解

1、el-ui中实现某一列为复选框 实现多选非常简单: 手动添加一个el-table-column，设type属性为selction即可； 2、@selection-change事件：选项发生勾选状态变化时触发该事件 <el-table @sel...

everthing

21
0