root / HServer / 00.Server / 00.Program / node_modules / node.extend / Readme.md
이력 | 보기 | 이력해설 | 다운로드 (2.03 KB)
| 1 |
# node.extend |
|---|---|
| 2 |
|
| 3 |
A port of jQuery.extend that **actually works** on node.js |
| 4 |
|
| 5 |
[![Build Status][3]][4] [![dependency status][5]][6] |
| 6 |
|
| 7 |
[![browser support][1]][2] |
| 8 |
|
| 9 |
|
| 10 |
## Description |
| 11 |
|
| 12 |
None of the existing ones on npm really work therefore I ported it myself. |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
## Usage |
| 17 |
|
| 18 |
To install this module in your current working directory (which should already contain a package.json), run |
| 19 |
|
| 20 |
``` |
| 21 |
npm install node.extend |
| 22 |
``` |
| 23 |
|
| 24 |
You can additionally just list the module in your [package.json](https://npmjs.org/doc/json.html) and run npm install. |
| 25 |
|
| 26 |
Then, require this package where you need it: |
| 27 |
|
| 28 |
``` |
| 29 |
var extend = require('node.extend');
|
| 30 |
``` |
| 31 |
|
| 32 |
The syntax for merging two objects is as follows: |
| 33 |
|
| 34 |
``` |
| 35 |
var destObject = extend({}, sourceObject);
|
| 36 |
// Where sourceObject is the object whose properties will be copied into another. |
| 37 |
// NOTE: In this situation, this is not a deep merge. See below on how to handle a deep merge. |
| 38 |
``` |
| 39 |
|
| 40 |
For information about how the clone works internally, view source in lib/extend.js or checkout the doc from [jQuery][] |
| 41 |
|
| 42 |
### A Note About Deep Merge (avoiding pass-by-reference cloning) |
| 43 |
|
| 44 |
In order to force a deep merge, when extending an object, you must pass boolean true as the first argument to extend: |
| 45 |
|
| 46 |
``` |
| 47 |
var destObject = extend(true, {}, sourceObject);
|
| 48 |
// Where sourceObject is the object whose properties will be copied into another. |
| 49 |
``` |
| 50 |
|
| 51 |
See [this article](http://www.jon-carlos.com/2013/is-javascript-call-by-value-or-call-by-reference/) for more information about the need for deep merges in JavaScript. |
| 52 |
|
| 53 |
## Credit |
| 54 |
|
| 55 |
- Jordan Harband [@ljharb][] |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
## License |
| 60 |
|
| 61 |
Copyright 2011, John Resig |
| 62 |
Dual licensed under the MIT or GPL Version 2 licenses. |
| 63 |
http://jquery.org/license |
| 64 |
|
| 65 |
[1]: https://ci.testling.com/dreamerslab/node.extend.png |
| 66 |
[2]: https://ci.testling.com/dreamerslab/node.extend |
| 67 |
[3]: https://travis-ci.org/dreamerslab/node.extend.png |
| 68 |
[4]: https://travis-ci.org/dreamerslab/node.extend |
| 69 |
[5]: https://david-dm.org/dreamerslab/node.extend.png |
| 70 |
[6]: https://david-dm.org/dreamerslab/node.extend |
| 71 |
[jQuery]: http://api.jquery.com/jQuery.extend/ |
| 72 |
[@ljharb]: https://twitter.com/ljharb |
| 73 |
|