88( function ( define ) { 'use strict' ;
99define ( function ( ) {
1010
11- var undef ;
11+ var undef , universalApply ;
12+
13+ universalApply = require ( './universalApply' ) ;
1214
1315 /**
1416 * Creates an object by either invoking ctor as a function and returning the result,
@@ -26,42 +28,19 @@ define(function() {
2628 var begotten , ctorResult ;
2729
2830 if ( forceConstructor || ( forceConstructor === undef && isConstructor ( ctor ) ) ) {
29- begotten = Object . create ( ctor . prototype ) ;
30- defineConstructorIfPossible ( begotten , ctor ) ;
31- ctorResult = ctor . apply ( begotten , args ) ;
31+ begotten = ctor ;
32+ ctorResult = universalApply ( ctor , begotten , args ) ;
33+
3234 if ( ctorResult !== undef ) {
3335 begotten = ctorResult ;
3436 }
35-
3637 } else {
37- begotten = ctor . apply ( undef , args ) ;
38-
38+ begotten = universalApply ( ctor , undef , args ) ;
3939 }
4040
4141 return begotten === undef ? null : begotten ;
4242 } ;
4343
44- /**
45- * Carefully sets the instance's constructor property to the supplied
46- * constructor, using Object.defineProperty if available. If it can't
47- * set the constructor in a safe way, it will do nothing.
48- *
49- * @param instance {Object} component instance
50- * @param ctor {Function} constructor
51- */
52- function defineConstructorIfPossible ( instance , ctor ) {
53- try {
54- Object . defineProperty ( instance , 'constructor' , {
55- value : ctor ,
56- enumerable : false
57- } ) ;
58- } catch ( e ) {
59- // If we can't define a constructor, oh well.
60- // This can happen if in envs where Object.defineProperty is not
61- // available, or when using cujojs/poly or other ES5 shims
62- }
63- }
64-
6544 /**
6645 * Determines whether the supplied function should be invoked directly or
6746 * should be invoked using new in order to create the object to be wired.
@@ -72,10 +51,13 @@ define(function() {
7251 */
7352 function isConstructor ( func ) {
7453 var is = false , p ;
75- for ( p in func . prototype ) {
76- if ( p !== undef ) {
77- is = true ;
78- break ;
54+
55+ if ( ! is ) {
56+ for ( p in func . prototype ) {
57+ if ( p !== undef ) {
58+ is = true ;
59+ break ;
60+ }
7961 }
8062 }
8163
0 commit comments