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

invoke

优质
小牛编辑
125浏览
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]();
  });
}
NameType(s)Description
methodNamestring

The name of the method to invoke for every element in this sequence.

returnsSequence

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"]