{"action":"created","issue":{"url":"https://api.github.com/repos/angular/angular.js/issues/12597","labels_url":"https://api.github.com/repos/angular/angular.js/issues/12597/labels{/name}","comments_url":"https://api.github.com/repos/angular/angular.js/issues/12597/comments","events_url":"https://api.github.com/repos/angular/angular.js/issues/12597/events","html_url":"https://github.com/angular/angular.js/issues/12597","id":101387747,"number":12597,"title":"$injector cannot instantiate ES6 classes","user":{"login":"mprobst","id":7208,"avatar_url":"https://avatars.githubusercontent.com/u/7208?v=3","gravatar_id":"","url":"https://api.github.com/users/mprobst","html_url":"https://github.com/mprobst","followers_url":"https://api.github.com/users/mprobst/followers","following_url":"https://api.github.com/users/mprobst/following{/other_user}","gists_url":"https://api.github.com/users/mprobst/gists{/gist_id}","starred_url":"https://api.github.com/users/mprobst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mprobst/subscriptions","organizations_url":"https://api.github.com/users/mprobst/orgs","repos_url":"https://api.github.com/users/mprobst/repos","events_url":"https://api.github.com/users/mprobst/events{/privacy}","received_events_url":"https://api.github.com/users/mprobst/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/angular/angular.js/labels/branch:%201.4.x","name":"branch: 1.4.x","color":"fad8c7"},{"url":"https://api.github.com/repos/angular/angular.js/labels/component:%20di","name":"component: di","color":"d4c5f9"},{"url":"https://api.github.com/repos/angular/angular.js/labels/type:%20bug","name":"type: bug","color":"000000"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/angular/angular.js/milestones/27","html_url":"https://github.com/angular/angular.js/milestones/Backlog","labels_url":"https://api.github.com/repos/angular/angular.js/milestones/27/labels","id":489171,"number":27,"title":"Backlog","description":"Holds the backlog of issues and pull requests that have been triaged.\r\n\r\nBefore assigning items to this milestone they should be labelled, at the very least with the correct \"type\" label (i.e. \"issue\", \"pr\", \"bug\", \"regression\", \"chore\", \"docs\", etc).  Preferably you should also check for duplicate issues/PRs, note CLA status and assign \"complexity\" and \"impact\" labels too.","creator":{"login":"IgorMinar","id":216296,"avatar_url":"https://avatars.githubusercontent.com/u/216296?v=3","gravatar_id":"","url":"https://api.github.com/users/IgorMinar","html_url":"https://github.com/IgorMinar","followers_url":"https://api.github.com/users/IgorMinar/followers","following_url":"https://api.github.com/users/IgorMinar/following{/other_user}","gists_url":"https://api.github.com/users/IgorMinar/gists{/gist_id}","starred_url":"https://api.github.com/users/IgorMinar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IgorMinar/subscriptions","organizations_url":"https://api.github.com/users/IgorMinar/orgs","repos_url":"https://api.github.com/users/IgorMinar/repos","events_url":"https://api.github.com/users/IgorMinar/events{/privacy}","received_events_url":"https://api.github.com/users/IgorMinar/received_events","type":"User","site_admin":false},"open_issues":681,"closed_issues":1005,"state":"open","created_at":"2013-11-18T23:30:35Z","updated_at":"2015-10-15T20:34:43Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2015-08-17T10:14:08Z","updated_at":"2015-10-20T20:45:03Z","closed_at":null,"body":"This code (paraphrasing) fails with `TypeError: Class constructors cannot be invoked without 'new'`:\r\n\r\n```js\r\nclass Foo { constructor() { } }\r\nvar foo = $injector.instantiate(Foo);\r\n```\r\n\r\nThe reason is that ES6 disallows using `fn.apply` on class constructors."},"comment":{"url":"https://api.github.com/repos/angular/angular.js/issues/comments/149696567","html_url":"https://github.com/angular/angular.js/issues/12597#issuecomment-149696567","issue_url":"https://api.github.com/repos/angular/angular.js/issues/12597","id":149696567,"user":{"login":"bisubus","id":2905949,"avatar_url":"https://avatars.githubusercontent.com/u/2905949?v=3","gravatar_id":"","url":"https://api.github.com/users/bisubus","html_url":"https://github.com/bisubus","followers_url":"https://api.github.com/users/bisubus/followers","following_url":"https://api.github.com/users/bisubus/following{/other_user}","gists_url":"https://api.github.com/users/bisubus/gists{/gist_id}","starred_url":"https://api.github.com/users/bisubus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bisubus/subscriptions","organizations_url":"https://api.github.com/users/bisubus/orgs","repos_url":"https://api.github.com/users/bisubus/repos","events_url":"https://api.github.com/users/bisubus/events{/privacy}","received_events_url":"https://api.github.com/users/bisubus/received_events","type":"User","site_admin":false},"created_at":"2015-10-20T20:45:03Z","updated_at":"2015-10-20T20:45:03Z","body":"@mprobst I've encountered the similar issue before and ended by splitting the solution into separate extension, [ng-classified](https://github.com/ex-machine/ng-classified).\r\n\r\nJust have checked #12598, I have a feeling that patching up `instantiate` is halfhearted job, it will just affect performance by propagating `new` everywhere and not targeting the classes. And other things that could benefit from classes will still get their TypeErrors (the world is bigger than controllers).\r\n\r\nIt is evident that I've managed it more drastically, it is `$injector.invoke` which is primarily responsible for calling class constructors directly. And I consider it the right idea because it is a great opportunity to pull up mature 1.x to fit contemporary expectations (particularly excited by Angular 2) by using DI-enabled classes everywhere where 1.x would expect constructor functions, without breaking anything.\r\n\r\nIt's not that simple, what's good for extension, is bad for framework. Due to the fact that only Chrome/V8 native class implementation can be easily detected (even FF native classes appear as functions for now), I've had to introduce some conventions and [add flag checks](https://github.com/ex-machine/ng-classified/blob/1.0.0/src/ng-classified.js#L57) to avoid trying-catching TypeErrors on every invoke.\r\n\r\nIs it acceptable to make `$injector` configurable on framework level? I'm not sure at all. But I think it is inevitable to provide some degree of configurability to deal with classes in future-proof manner while keeping the performance high for classless apps."}}