extend.js
658 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
Example usage:
var A = Class(function() {
var defaults = {
foo: 'cat',
bar: 'dum'
}
this.init = function(opts) {
opts = std.extend(opts, defaults)
this._foo = opts.foo
this._bar = opts.bar
}
this.getFoo = function() {
return this._foo
}
this.getBar = function() {
return this._bar
}
})
var a = new A({ bar:'sim' })
a.getFoo() == 'cat'
a.getBar() == 'sim'
*/
var copy = require('./copy')
module.exports = function extend(target, extendWith) {
target = copy(target)
for (var key in extendWith) {
if (typeof target[key] != 'undefined') { continue }
target[key] = extendWith[key]
}
return target
}