Javascript Delete Reference type Object _javascript tips

Source: Internet
Author: User

As in the following example:

Copy Code code as follows:

var TestVar = {
A: {
Test:1
}
},
Test1 = {},
Test2 = {};

test1.a = TESTVAR.A;
test2.a = TESTVAR.A;
/*
Delete test1.a;
Console.log (test1.a); Undefined
Console.log (test2.a); Object {test: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

As you can see from the test, the deleted object of JavaScript Delete is a reference type, and it deletes not the referenced object but the pointer to the referenced object. Therefore, even if delete testvar.a, the object that test1.a points to is still not deleted.

For more information on the principles of JavaScript Delete keywords, recommend:

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

Translated version:

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.