通过参考,请查看此 jsfiddle 以获取证据:
http://jsfiddle.net/3wntu/1/
HTML:
<div >Shifted obj title: <span id='display1'></span></div>
<div >firstObj title: <span id='display2'></span></div>
<div >obj1 title: <span id='display3'></span></div>
js:
var myArray = [],
firstElement = {},
obj1 = {title:'obj1'},
obj2 = {title: 'obj2'},
obj3 = {title: 'obj3'};
myArray.push(obj1);
myArray.push(obj2);
myArray.push(obj3);
firstElement = myArray.shift();
document.getElementById("display1").innerHTML = firstElement.title;
//change the objects name
firstObj.title = "firstElement";
//output the reference object title
document.getElementById("display2").innerHTML = firstElement.title;
//output the original output - should be the same as the altered reference title
document.getElementById("display3").innerHTML = obj1.title;