2015/12/14-Object assignment problem and Ie8hack

Source: Internet
Author: User

Today, at work, I noticed that I didn't notice the place before, that is, if an object is assigned to another variable or object through the assignment operator "=", then the value or data of the object is not stored in the variable or object that receives the value, but only the this pointer to the object.

For example:

var x = {' A ': 1}var y = x;  The variable y holds not the contents of object X, but a this pointer, whose source is still the object X

So, once we have changed the contents of the variable y, the X object as the source will also change.

1 var x = {' A ': 1}2var y = x; 3 y.a=2 = x.a==2

If you want the variable y to hold the contents of object X, and you change the action variable y without changing the object x, you can only copy the object!

var function (obj) {     var result = {};          for (var in obj) {          typeof obj=== "Object"? CopyObject (Obj[x]): obj[x]        }
return result;}

------------------------------------------------Gorgeous split-line---------------------------------------------

In addition to the above harvest, but also solves a IE8 css hack problem.

1 . IE8{2 background:red\9;3      /*ie6-8; The first scenario: This scenario is often written in a CSS style sheet*/4 5 background:red\\9;6      /*ie6-8; Scenario Two: When this scheme can be used in inline styles*/7 8 background:red\0;9    /*Ie8-edge Support*/Ten}

2015/12/14-Object assignment problem and Ie8hack

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.