@@ -821,6 +821,14 @@ function createInjector(modulesToLoad, strictDi) {
821
821
return args ;
822
822
}
823
823
824
+ function isClass ( func ) {
825
+ // IE 9-11 do not support classes and IE9 leaks with the code below.
826
+ if ( msie <= 11 ) {
827
+ return false ;
828
+ }
829
+ return typeof func === 'function'
830
+ && / ^ c l a s s \s / . test ( Function . prototype . toString . call ( func ) ) ;
831
+ }
824
832
825
833
function invoke ( fn , self , locals , serviceName ) {
826
834
if ( typeof locals === 'string' ) {
@@ -833,9 +841,16 @@ function createInjector(modulesToLoad, strictDi) {
833
841
fn = fn [ fn . length - 1 ] ;
834
842
}
835
843
836
- // http://jsperf.com/angularjs-invoke-apply-vs-switch
837
- // #5388
838
- return fn . apply ( self , args ) ;
844
+ if ( ! isClass ( fn ) ) {
845
+ // http://jsperf.com/angularjs-invoke-apply-vs-switch
846
+ // #5388
847
+ return fn . apply ( self , args ) ;
848
+ } else {
849
+ args . unshift ( null ) ;
850
+ /*jshint -W058 */ // Applying a constructor without immediate parentheses is the point here.
851
+ return new ( Function . prototype . bind . apply ( fn , args ) ) ;
852
+ /*jshint +W058 */
853
+ }
839
854
}
840
855
841
856
@@ -845,7 +860,7 @@ function createInjector(modulesToLoad, strictDi) {
845
860
var ctor = ( isArray ( Type ) ? Type [ Type . length - 1 ] : Type ) ;
846
861
var args = injectionArgs ( Type , locals , serviceName ) ;
847
862
// Empty object at position 0 is ignored for invocation with `new`, but required.
848
- args . unshift ( { } ) ;
863
+ args . unshift ( null ) ;
849
864
/*jshint -W058 */ // Applying a constructor without immediate parentheses is the point here.
850
865
return new ( Function . prototype . bind . apply ( ctor , args ) ) ;
851
866
/*jshint +W058 */
0 commit comments