Home > Web Front-end > JS Tutorial > body text

Javascript delete reference type object_javascript skills

WBOY
Release: 2016-05-16 17:17:53
Original
980 people have browsed it

As an example below:

Copy code The code is as follows:

var testVar = {
a : {
test: 1
}
},
test1 = {},
test2 = {};

test1. a = testVar.a;
test2.a = testVar.a;
/*
                                                                                                delete test1.a; 1}
console.log(testVar.a); // Object {test: 1}
*/
delete testVar.a;
console.log(test1.a); // Object {test: 1}
console.log(test2.a); // Object {test: 1}
console.log(testVar.a); // undefined


Through testing, it can be seen that if the object deleted by JavaScript delete is a reference type, then it deletes not the referenced object, but the pointer to the referenced object. Therefore, even if you delete testVar.a, the object pointed by test1.a is still not deleted.

For more information on the principles of javascript delete keyword, we recommend:

http://perfectionkills.com/understanding-delete/

Translated version:

http://www.ituring.com.cn/article/7620

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template