Home >Web Front-end >JS Tutorial >Introduction to the differences between js objects created_Basic knowledge

Introduction to the differences between js objects created_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 16:41:081293browse

A : var obj1 = obj2 = new Object();

and

B : var obj1 = new Object(),
obj2 = new Object();

are two different assignment methods, resulting in different results. Please pay attention~

A will point the two objects to the same memory address, causing the contents of the two objects to be consistent

var t1 = t2 = new Object();
t1.name = 'hello';
t2.name = 'kao';
t1.name = null;
alert(t2.name); // 结果为 null

B’s will not

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn