|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# assignIn |
| 22 | + |
| 23 | +> Copy enumerable own and inherited properties from one or more source objects to a target object. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<!-- Package usage documentation. --> |
| 34 | + |
| 35 | +<section class="usage"> |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```javascript |
| 40 | +var assignIn = require( '@stdlib/object/assign-in' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### assignIn( target, source1\[, source2\[,...,sourceN]] ) |
| 44 | + |
| 45 | +Copies enumerable own and inherited properties from one or more source objects to a target object. |
| 46 | + |
| 47 | +```javascript |
| 48 | +function Foo() { |
| 49 | + this.a = 'beep'; |
| 50 | + return this; |
| 51 | +} |
| 52 | + |
| 53 | +Foo.prototype.b = 'boop'; |
| 54 | + |
| 55 | +var x = {}; |
| 56 | +var y = new Foo(); |
| 57 | + |
| 58 | +var z = assignIn( x, y ); |
| 59 | +// returns { 'a': 'beep', 'b': 'boop' } |
| 60 | + |
| 61 | +var bool = ( z === x ); |
| 62 | +// returns true |
| 63 | +``` |
| 64 | + |
| 65 | +</section> |
| 66 | + |
| 67 | +<!-- /.usage --> |
| 68 | + |
| 69 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 70 | + |
| 71 | +<section class="notes"> |
| 72 | + |
| 73 | +## Notes |
| 74 | + |
| 75 | +- If a property key is present in multiple sources, the property from the last source that defines the key prevails. |
| 76 | +- The target object is mutated. |
| 77 | +- Both string and symbol properties are copied. |
| 78 | + |
| 79 | +</section> |
| 80 | + |
| 81 | +<!-- /.notes --> |
| 82 | + |
| 83 | +<!-- Package usage examples. --> |
| 84 | + |
| 85 | +<section class="examples"> |
| 86 | + |
| 87 | +## Examples |
| 88 | + |
| 89 | +<!-- eslint no-undef: "error" --> |
| 90 | + |
| 91 | +```javascript |
| 92 | +var assign = require( '@stdlib/object/assign-in' ); |
| 93 | + |
| 94 | +function Foo() { |
| 95 | + this.a = 1; |
| 96 | + return this; |
| 97 | +} |
| 98 | + |
| 99 | +Foo.prototype.b = 2; |
| 100 | + |
| 101 | +function Bar() { |
| 102 | + this.c = 3; |
| 103 | + return this; |
| 104 | +} |
| 105 | + |
| 106 | +Bar.prototype.d = 4; |
| 107 | + |
| 108 | +var obj1 = new Foo(); |
| 109 | +var obj2 = new Bar(); |
| 110 | + |
| 111 | +var result = assignIn( {}, obj1, obj2 ); |
| 112 | +// returns { 'a': 1, 'b': 2, 'c': 3, 'd': 4 } |
| 113 | +``` |
| 114 | + |
| 115 | +</section> |
| 116 | + |
| 117 | +<!-- /.examples --> |
| 118 | + |
| 119 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 120 | + |
| 121 | +<section class="references"> |
| 122 | + |
| 123 | +</section> |
| 124 | + |
| 125 | +<!-- /.references --> |
| 126 | + |
| 127 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 128 | + |
| 129 | +<section class="related"> |
| 130 | + |
| 131 | +<!-- /.related --> |
| 132 | + |
| 133 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 134 | + |
| 135 | +<section class="links"> |
| 136 | + |
| 137 | +<!-- <related-links> --> |
| 138 | + |
| 139 | +<!-- </related-links> --> |
| 140 | + |
| 141 | +</section> |
| 142 | + |
| 143 | +<!-- /.links --> |
0 commit comments