As an example below:
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
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