@@ -36,7 +36,7 @@ var initializing = false,
3636 newProps [ name ] ;
3737 }
3838 } ;
39- // The base Class implementation (does nothing)
39+
4040
4141/**
4242* @constructor jQuery.Class
@@ -327,7 +327,8 @@ $.extend($.Class,{
327327 var cur = args . concat ( jQuery . makeArray ( arguments ) ) ,
328328 isString ,
329329 length = funcs . length ,
330- f = 0 , func ;
330+ f = 0 ,
331+ func ;
331332
332333 for ( ; f < length ; f ++ ) {
333334 if ( ! funcs [ f ] ) {
@@ -361,7 +362,7 @@ $.extend($.Class,{
361362 */
362363 getObject : function ( objectName , current ) {
363364 var current = current || window ,
364- parts = objectName . split ( / \. / )
365+ parts = objectName ? objectName . split ( / \. / ) : [ ] ;
365366 for ( var i = 0 ; i < parts . length ; i ++ ) {
366367 current = current [ parts [ i ] ] || ( current [ parts [ i ] ] = { } )
367368 }
@@ -378,13 +379,14 @@ $.extend($.Class,{
378379 * @codeend
379380 */
380381 newInstance : function ( ) {
381- initializing = true ;
382- var inst = new this ( ) ;
383- initializing = false ;
384- if ( inst . setup )
385- inst . setup . apply ( inst , arguments ) ;
386- if ( inst . init )
387- inst . init . apply ( inst , arguments ) ;
382+ var inst = this . rawInstance ( ) ,
383+ args ;
384+ if ( inst . setup ) {
385+ args = inst . setup . apply ( inst , arguments ) ;
386+ }
387+ if ( inst . init ) {
388+ inst . init . apply ( inst , $ . isArray ( args ) ? args : arguments ) ;
389+ }
388390 return inst ;
389391 } ,
390392 /**
@@ -421,92 +423,83 @@ $.extend($.Class,{
421423 * @return {jQuery.Class } returns the new class
422424 */
423425 extend : function ( fullName , klass , proto ) {
424-
426+ // figure out what was passed
425427 if ( typeof fullName != 'string' ) {
426428 proto = klass ;
427429 klass = fullName ;
428430 fullName = null ;
429431 }
430-
431432 if ( ! proto ) {
432433 proto = klass ;
433434 klass = null ;
434435 }
435436
436437 proto = proto || { } ;
437- var _super_class = this ;
438- var _super = this . prototype ;
438+ var _super_class = this ,
439+ _super = this . prototype ,
440+ name ,
441+ shortName ,
442+ namespace ,
443+ prototype ;
444+
439445 // Instantiate a base class (but only create the instance,
440446 // don't run the init constructor)
441447 initializing = true ;
442- var prototype = new this ( ) ;
448+ prototype = new this ( ) ;
443449 initializing = false ;
444450 // Copy the properties over onto the new prototype
445451 inheritProps ( proto , _super , prototype ) ;
446452
447453 // The dummy class constructor
448454 function Class ( ) {
449- // All construction is actually done in the init method
450- if ( initializing ) return ;
451-
452- if ( this . constructor !== Class && arguments . length ) { //we are being called w/o new
453- return this . extend . apply ( this , arguments )
454- } else { //we are being called w/ new
455- var args ;
456- if ( this . setup ) {
457- args = this . setup . apply ( this , arguments ) ;
458- }
459- if ( this . init ) {
460- this . init . apply ( this , $ . isArray ( args ) ? args : arguments ) ;
461- }
462-
463- }
455+ // All construction is actually done in the init method
456+ if ( initializing ) return ;
457+
458+ if ( this . constructor !== Class && arguments . length ) { //we are being called w/o new
459+ return this . extend . apply ( this , arguments )
460+ } else { //we are being called w/ new
461+ return this . Class . newInstance . apply ( this . Class , arguments )
462+ }
464463 }
465- for ( var name in this ) {
464+ // Copy old stuff onto class
465+ for ( name in this ) {
466466 if ( this . hasOwnProperty ( name ) &&
467- name != 'prototype' &&
468- name != 'defaults' &&
469- name != 'getObject' ) {
467+ $ . inArray ( name , [ 'prototype' , 'defaults' , 'getObject' ] ) == - 1 ) {
470468 Class [ name ] = this [ name ] ;
471469 }
472470 }
473-
474-
475-
476-
477- //copy properties from current class to static
478-
479471
480- //do static inheritence
481- inheritProps ( klass , this , Class )
482-
483-
484- var shortName ,
485- namespace ;
472+ // do static inheritence
473+ inheritProps ( klass , this , Class ) ;
486474
475+ // do namespace stuff
487476 if ( fullName ) {
488- var current = window
489- var parts = fullName . split ( / \. / )
490- for ( var i = 0 ; i < parts . length - 1 ; i ++ ) {
491- current = current [ parts [ i ] ] || ( current [ parts [ i ] ] = { } )
492- }
493- namespace = current ;
494- shortName = parts [ parts . length - 1 ] ;
495477
478+ var parts = fullName . split ( / \. / ) ,
479+ shortName = parts . pop ( ) ;
480+ current = $ . Class . getObject ( parts . join ( '.' ) ) ,
481+ namespace = current ;
482+
496483 //@steal -remove-start
497484 steal . dev . isHappyName ( fullName )
498485 //@steal -remove-end
486+
487+ current [ shortName ] = Class ;
499488 }
500489
501- Class . prototype = prototype ;
502- //Provide a reference to this class
503- Class . prototype . Class = Class ; //only changing buff prototype
504- Class . prototype . constructor = Class ; //only buff prototype
505- // Enforce the constructor to be what we expect
506- Class . constructor = Class ;
490+ //set things that can't be overwritten
491+ $ . extend ( Class , {
492+ prototype : prototype ,
493+ namespace : namespace ,
494+ shortName : shortName ,
495+ constructor : Class ,
496+ fullName : fullName
497+ } ) ;
507498
508- Class . namespace = namespace ;
509- Class . shortName = shortName
499+ //make sure our prototype looks nice
500+ Class . prototype . Class = Class . prototype . constructor = Class ;
501+
502+
510503 /**
511504 * @attribute fullName
512505 * The full name of the class, including namespace, provided for introspection purposes.
@@ -516,9 +509,7 @@ $.extend($.Class,{
516509 * MyOrg.MyClass.fullName //-> 'MyOrg.MyClass'
517510 * @codeend
518511 */
519- Class . fullName = fullName ;
520-
521-
512+
522513 var args = Class . setup . apply ( Class , [ _super_class ] . concat ( $ . makeArray ( arguments ) ) ) ;
523514
524515 if ( Class . init ) {
@@ -527,12 +518,6 @@ $.extend($.Class,{
527518
528519 /* @Prototype */
529520
530-
531- if ( shortName ) {
532- current [ shortName ] = Class ;
533- }
534-
535-
536521 return Class ;
537522 /**
538523 * @function setup
0 commit comments