当前位置: 首页 > 文档资料 > Lazy.js 英文文档 >

defaults

优质
小牛编辑
134浏览
2023-12-01

Returns an ObjectLikeSequence whose elements are the combination of this sequence and a 'default' object. In the case of a key appearing in both this sequence and the given object, this sequence's value will override the default object's.

Signature

ObjectLikeSequence.defaults = function(defaults) { /*...*/ }
ObjectLikeSequence.defaults = function defaults(defaults) {
  return new DefaultsSequence(this, defaults);
}
NameType(s)Description
defaultsObject

The 'default' object to use for missing keys in this sequence.

returnsObjectLikeSequence

A new sequence comprising elements from this sequence supplemented by the contents of defaults.

Examples

Lazy({ name: "Dan" }).defaults({ name: "User", password: "passw0rd" }) // sequence: { name: "Dan", password: "passw0rd" }
Lazy({ foo: false }).defaults({ foo: 'foo' }).get('foo') // false
Lazy({ a: 1 }).defaults({ b: 2 }).defaults({ c: 3 }) // sequence: { a: 1, b: 2, c: 3 }
Lazy({ a: 1 }).defaults({ b: 2 }).defaults({ a: 3 }) // sequence: { a: 1, b: 2 }
Lazy({ a: 1, b: 2 }).defaults({ b: 5 }).defaults({ c: 3, d: 4 }) // sequence: { a: 1, b: 2, c: 3, d: 4 }