Skip to content

Commit 6411cdf

Browse files
committed
Rename $.extend2 to $.widget.extend
1 parent 8b06707 commit 6411cdf

File tree

3 files changed

+41
-42
lines changed

3 files changed

+41
-42
lines changed

tests/unit/widget/widget.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<script src="../testsuite.js"></script>
1515

1616
<script src="widget_core.js"></script>
17-
<script src="extend2.js"></script>
17+
<script src="widget_extend.js"></script>
1818

1919
<script src="../swarminject.js"></script>
2020
</head>

tests/unit/widget/extend2.js renamed to tests/unit/widget/widget_extend.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test("jQuery.extend(Object, Object)", function() {
1+
test("$.widget.extend(Object, Object)", function() {
22
expect(28);
33

44
var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
@@ -13,62 +13,62 @@ test("jQuery.extend(Object, Object)", function() {
1313
arr = [1, 2, 3],
1414
nestedarray = { arr: arr };
1515

16-
jQuery.extend2(settings, options);
16+
$.widget.extend(settings, options);
1717
same( settings, merged, "Check if extended: settings must be extended" );
1818
same( options, optionsCopy, "Check if not modified: options must not be modified" );
19-
jQuery.extend2(settings, null, options);
19+
$.widget.extend(settings, null, options);
2020
same( settings, merged, "Check if extended: settings must be extended" );
2121
same( options, optionsCopy, "Check if not modified: options must not be modified" );
2222

23-
jQuery.extend2(deep1, deep2);
23+
$.widget.extend(deep1, deep2);
2424
same( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
2525
same( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
2626
equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
2727

28-
ok( jQuery.extend2({}, nestedarray).arr === arr, "Don't clone arrays" );
29-
ok( jQuery.isPlainObject( jQuery.extend2({ arr: arr }, { arr: {} }).arr ), "Cloned object heve to be an plain object" );
28+
ok( $.widget.extend({}, nestedarray).arr === arr, "Don't clone arrays" );
29+
ok( jQuery.isPlainObject( $.widget.extend({ arr: arr }, { arr: {} }).arr ), "Cloned object heve to be an plain object" );
3030

3131
var empty = {};
3232
var optionsWithLength = { foo: { length: -1 } };
33-
jQuery.extend2(empty, optionsWithLength);
33+
$.widget.extend(empty, optionsWithLength);
3434
same( empty.foo, optionsWithLength.foo, "The length property must copy correctly" );
3535

3636
empty = {};
3737
var optionsWithDate = { foo: { date: new Date } };
38-
jQuery.extend2(empty, optionsWithDate);
38+
$.widget.extend(empty, optionsWithDate);
3939
same( empty.foo, optionsWithDate.foo, "Dates copy correctly" );
4040

4141
var myKlass = function() {};
4242
var customObject = new myKlass();
4343
var optionsWithCustomObject = { foo: { date: customObject } };
4444
empty = {};
45-
jQuery.extend2(empty, optionsWithCustomObject);
45+
$.widget.extend(empty, optionsWithCustomObject);
4646
ok( empty.foo && empty.foo.date === customObject, "Custom objects copy correctly (no methods)" );
4747

4848
// Makes the class a little more realistic
4949
myKlass.prototype = { someMethod: function(){} };
5050
empty = {};
51-
jQuery.extend2(empty, optionsWithCustomObject);
51+
$.widget.extend(empty, optionsWithCustomObject);
5252
ok( empty.foo && empty.foo.date === customObject, "Custom objects copy correctly" );
5353

54-
var ret = jQuery.extend2({ foo: 4 }, { foo: new Number(5) } );
54+
var ret = $.widget.extend({ foo: 4 }, { foo: new Number(5) } );
5555
ok( ret.foo == 5, "Wrapped numbers copy correctly" );
5656

5757
var nullUndef;
58-
nullUndef = jQuery.extend2({}, options, { xnumber2: null });
58+
nullUndef = $.widget.extend({}, options, { xnumber2: null });
5959
ok( nullUndef.xnumber2 === null, "Check to make sure null values are copied");
6060

61-
nullUndef = jQuery.extend2({}, options, { xnumber2: undefined });
61+
nullUndef = $.widget.extend({}, options, { xnumber2: undefined });
6262
ok( nullUndef.xnumber2 === options.xnumber2, "Check to make sure undefined values are not copied");
6363

64-
nullUndef = jQuery.extend2({}, options, { xnumber0: null });
64+
nullUndef = $.widget.extend({}, options, { xnumber0: null });
6565
ok( nullUndef.xnumber0 === null, "Check to make sure null values are inserted");
6666

6767
// TODO weird test
6868
/*
6969
var target = {};
7070
var recursive = { foo:target, bar:5 };
71-
jQuery.extend2(target, recursive);
71+
$.widget.extend(target, recursive);
7272
same( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
7373
*/
7474

@@ -106,7 +106,7 @@ test("jQuery.extend(Object, Object)", function() {
106106
var input = {
107107
key: [ 1, 2, 3 ]
108108
}
109-
var output = jQuery.extend2( {}, input );
109+
var output = $.widget.extend( {}, input );
110110
deepEqual( input, output, "don't clone arrays" );
111111
input.key[0] = 10;
112112
deepEqual( input, output, "don't clone arrays" );

ui/jquery.ui.widget.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,6 @@
1111

1212
var slice = Array.prototype.slice;
1313

14-
function extend( target ) {
15-
var input = slice.call( arguments, 1 ),
16-
inputIndex = 0,
17-
inputLength = input.length,
18-
key,
19-
value;
20-
for ( ; inputIndex < inputLength; inputIndex++ ) {
21-
for ( key in input[ inputIndex ] ) {
22-
value = input[ inputIndex ][ key ];
23-
if (input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
24-
target[ key ] = $.isPlainObject( value ) ? extend( {}, target[ key ], value ) : value;
25-
}
26-
}
27-
}
28-
return target;
29-
}
30-
$.extend2 = extend;
31-
3214
var _cleanData = $.cleanData;
3315
$.cleanData = function( elems ) {
3416
for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
@@ -56,7 +38,7 @@ $.widget = function( name, base, prototype ) {
5638
$[ namespace ] = $[ namespace ] || {};
5739
// create the constructor using $.extend() so we can carry over any
5840
// static properties stored on the existing constructor (if there is one)
59-
$[ namespace ][ name ] = $.extend( function( options, element ) {
41+
$[ namespace ][ name ] = $.widget.extend( function( options, element ) {
6042
// allow instantiation without "new" keyword
6143
if ( !this._createWidget ) {
6244
return new $[ namespace ][ name ]( options, element );
@@ -73,7 +55,7 @@ $.widget = function( name, base, prototype ) {
7355
// we need to make the options hash a property directly on the new instance
7456
// otherwise we'll modify the options hash on the prototype that we're
7557
// inheriting from
76-
basePrototype.options = extend( {}, basePrototype.options );
58+
basePrototype.options = $.widget.extend( {}, basePrototype.options );
7759
$.each( prototype, function( prop, value ) {
7860
if ( $.isFunction( value ) ) {
7961
prototype[ prop ] = (function() {
@@ -101,7 +83,7 @@ $.widget = function( name, base, prototype ) {
10183
}());
10284
}
10385
});
104-
$[ namespace ][ name ].prototype = extend( basePrototype, {
86+
$[ namespace ][ name ].prototype = $.widget.extend( basePrototype, {
10587
namespace: namespace,
10688
widgetName: name,
10789
widgetEventPrefix: name,
@@ -111,6 +93,23 @@ $.widget = function( name, base, prototype ) {
11193
$.widget.bridge( name, $[ namespace ][ name ] );
11294
};
11395

96+
$.widget.extend = function( target ) {
97+
var input = slice.call( arguments, 1 ),
98+
inputIndex = 0,
99+
inputLength = input.length,
100+
key,
101+
value;
102+
for ( ; inputIndex < inputLength; inputIndex++ ) {
103+
for ( key in input[ inputIndex ] ) {
104+
value = input[ inputIndex ][ key ];
105+
if (input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
106+
target[ key ] = $.isPlainObject( value ) ? $.widget.extend( {}, target[ key ], value ) : value;
107+
}
108+
}
109+
}
110+
return target;
111+
};
112+
114113
$.widget.bridge = function( name, object ) {
115114
$.fn[ name ] = function( options ) {
116115
var isMethodCall = typeof options === "string",
@@ -119,7 +118,7 @@ $.widget.bridge = function( name, object ) {
119118

120119
// allow multiple hashes to be passed on init
121120
options = !isMethodCall && args.length ?
122-
extend.apply( null, [ options ].concat(args) ) :
121+
$.widget.extend.apply( null, [ options ].concat(args) ) :
123122
options;
124123

125124
if ( isMethodCall ) {
@@ -181,7 +180,7 @@ $.Widget.prototype = {
181180
_createWidget: function( options, element ) {
182181
element = $( element || this.defaultElement || this )[ 0 ];
183182
this.element = $( element );
184-
this.options = extend( {},
183+
this.options = $.widget.extend( {},
185184
this.options,
186185
this._getCreateOptions(),
187186
options );
@@ -236,7 +235,7 @@ $.Widget.prototype = {
236235

237236
if ( arguments.length === 0 ) {
238237
// don't return a reference to the internal hash
239-
return extend( {}, this.options );
238+
return $.widget.extend( {}, this.options );
240239
}
241240

242241
if ( typeof key === "string" ) {
@@ -248,7 +247,7 @@ $.Widget.prototype = {
248247
parts = key.split( "." );
249248
key = parts.shift();
250249
if ( parts.length ) {
251-
curOption = options[ key ] = extend( {}, this.options[ key ] );
250+
curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
252251
for ( i = 0; i < parts.length - 1; i++ ) {
253252
curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
254253
curOption = curOption[ parts[ i ] ];

0 commit comments

Comments
 (0)