JS copies the properties of all object s to object R

Source: Internet
Author: User

This article mainly introduces the method of copying all object S's attribute to object R in JS, the native Js+jquery realizes

Native writing: Code as follows:/** * Copies all s properties to R * @param r {Object} * @param s {object} * @param is_overwrite {Boolean} as specified as False, no existing value is overwritten, other values * include undefined, which means that an attribute with the same name in S will overwrite the value in R/Mix:function (R, S, is_overwrite) {//todo:if      (!s | |!r) return r; For (var p in s) {if (Is_overwrite!== false | |!) (     P in R)) {R[p] = s[p];   } return R; jquery is too handy to write. Copy code code as follows: Var a={aa:1, ab:2};       var b={ba:1, bb:2};     $.extend (A,B); Console.info (a);

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.