invoke
优质
小牛编辑
129浏览
2023-12-01
Creates a new sequence whose values are calculated by invoking the specified function on each element in this sequence.
Signature
Sequence.invoke = function(methodName) { /*...*/ }
Sequence.invoke = function invoke(methodName) { return this.map(function(e) { return e[methodName](); }); }
Name | Type(s) | Description |
---|---|---|
methodName | string | The name of the method to invoke for every element in this sequence. |
returns | Sequence | The new sequence. |
Examples
function Person(first, last) { this.fullName = function fullName() { return first + " " + last; }; } var people = [ new Person("Dan", "Tao"), new Person("Bob", "Smith") ]; Lazy(people).invoke("fullName") // sequence: ["Dan Tao", "Bob Smith"]