Skip to content

Use Array.from instead of [].slice #963

@KSXGitHub

Description

@KSXGitHub

Example code

function * gen ()
  yield 123
  yield 456
  yield 789

console.log [...gen()]

Expected JavaScript

function* gen(){
  (yield 123);
  (yield 456);
  return (yield 789);
}
console.log(Array.from(gen())); // This would print [123, 456, 789]

Current JavaScript

var slice$ = [].slice;
function* gen(){
  (yield 123);
  (yield 456);
  return (yield 789);
}
console.log(slice$.call(gen())); // This would print an empty array

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions