{"action":"created","issue":{"url":"https://api.github.com/repos/babel/babel/issues/830","labels_url":"https://api.github.com/repos/babel/babel/issues/830/labels{/name}","comments_url":"https://api.github.com/repos/babel/babel/issues/830/comments","events_url":"https://api.github.com/repos/babel/babel/issues/830/events","html_url":"https://github.com/babel/babel/issues/830","id":58197409,"number":830,"title":"Optimization oppertunity: Rewrite call() with spread to apply","user":{"login":"realityking","id":628508,"avatar_url":"https://avatars.githubusercontent.com/u/628508?v=3","gravatar_id":"","url":"https://api.github.com/users/realityking","html_url":"https://github.com/realityking","followers_url":"https://api.github.com/users/realityking/followers","following_url":"https://api.github.com/users/realityking/following{/other_user}","gists_url":"https://api.github.com/users/realityking/gists{/gist_id}","starred_url":"https://api.github.com/users/realityking/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realityking/subscriptions","organizations_url":"https://api.github.com/users/realityking/orgs","repos_url":"https://api.github.com/users/realityking/repos","events_url":"https://api.github.com/users/realityking/events{/privacy}","received_events_url":"https://api.github.com/users/realityking/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-02-19T11:38:08Z","updated_at":"2015-02-19T11:56:10Z","closed_at":null,"body":"I think there's an optimzation oppertunity when code uses `call` with the spread operator. Since both `call` and `apply` are relativly slow, this might be intresting.\r\n\r\nMy test code\r\n```javascript\r\nfunction Canceller() {\r\n  this.a = {};\r\n  this.callback = function() {\r\n    console.log(this);\r\n  }\r\n}\r\nCanceller.prototype.test = function () {\r\n  var args = []\r\n  \r\n  return this.callback.call(undefined ,...args, this.a);\r\n};\r\n\r\nvar c = new Canceller();\r\nc.test();\r\n```\r\n\r\nThis currently generates the following code\r\n```javascript\r\n\"use strict\";\r\n\r\nfunction Canceller() {\r\n  this.a = {};\r\n  this.callback = function () {\r\n    console.log(this);\r\n  };\r\n}\r\nCanceller.prototype.test = function () {\r\n  var _callback;\r\n  var args = [];\r\n\r\n  return (_callback = this.callback).call.apply(_callback, [undefined].concat(args, [this.a]));\r\n};\r\n\r\nvar c = new Canceller();\r\nc.test();\r\n```\r\n\r\nHowever the `test` function would be better written like this:\r\n\r\n```javascript\r\nCanceller.prototype.test = function () {\r\n  var _callback;\r\n  var args = [];\r\n\r\n  return this.callback.call(undefined, args.concat([this.a]));\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/babel/babel/issues/comments/75040361","html_url":"https://github.com/babel/babel/issues/830#issuecomment-75040361","issue_url":"https://api.github.com/repos/babel/babel/issues/830","id":75040361,"user":{"login":"sebmck","id":853712,"avatar_url":"https://avatars.githubusercontent.com/u/853712?v=3","gravatar_id":"","url":"https://api.github.com/users/sebmck","html_url":"https://github.com/sebmck","followers_url":"https://api.github.com/users/sebmck/followers","following_url":"https://api.github.com/users/sebmck/following{/other_user}","gists_url":"https://api.github.com/users/sebmck/gists{/gist_id}","starred_url":"https://api.github.com/users/sebmck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebmck/subscriptions","organizations_url":"https://api.github.com/users/sebmck/orgs","repos_url":"https://api.github.com/users/sebmck/repos","events_url":"https://api.github.com/users/sebmck/events{/privacy}","received_events_url":"https://api.github.com/users/sebmck/received_events","type":"User","site_admin":false},"created_at":"2015-02-19T11:56:10Z","updated_at":"2015-02-19T11:56:10Z","body":"Yep. You'd be breaking code in very subtle ways that would be a nightmare for people to debug since it wouldn't be a result of their code.\r\n\r\nAlso\r\n\r\n```javascript\r\nreturn this.callback.call(undefined ,...args, this.a);\r\n```\r\n\r\ncan be rewritten as\r\n\r\n```javascript\r\nreturn this.callback.apply(undefined, [...args, this.a]);\r\n```\r\n\r\nWhich basically gives you exactly what you want."}}