Opened 14 years ago

Closed 13 years ago

#5303 closed bug (notabug)

An object that is supplied as an option value on instantiation will not end up on the instance (but a clone will)

Reported by: timmolendijk Owned by:
Priority: major Milestone: 1.8
Component: ui.widget Version: 1.8rc3
Keywords: object option value identity deep-copy clone Cc:
Blocked by: Blocking:


If you do:

var somedata = {x: 1};

$('#element').mywidget({data: somedata});

You would expect:

somedata === $('#element').mywidget('option', 'data')

Yet this is not the case!

I suspect this is caused by the deep-copy at jquery.ui.widget.js:57:

	$[ namespace ][ name ].prototype = $.extend( true, basePrototype, {
		namespace: namespace,
		widgetName: name,
		widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name,
		widgetBaseClass: fullName
	}, prototype );

P.S. Line 57 is where this code occurs in 1.8rc1, but the problem applies to 1.8rc3 as well.

Change History (6)

comment:1 Changed 14 years ago by timmolendijk

On second thought I think the cause is the deep-copy at jquery.ui.widget.js:73:

		// allow multiple hashes to be passed on init
		options = !isMethodCall && args.length ?
			$.extend.apply( null, [ true, options ].concat(args) ) :

comment:2 Changed 14 years ago by timmolendijk

On third thought I'm pretty sure the deep-copy at jquery.ui.widget.js:129 is causing this problem:

		this.options = $.extend( true, {},
			$.metadata && $.metadata.get( element )[ this.widgetName ],
			options );

comment:3 Changed 14 years ago by Scott González

Resolution: invalid
Status: newclosed

We don't claim anywhere that the options hash originally supplied would be the options hash that actually gets used. This is not a bug.

comment:4 Changed 14 years ago by timmolendijk

  1. I'm not talking about the options hash, I'm talking about the values of options.
  1. Wouldn't you agree that it is to be expected, or at least to be desired that if you supply an object x as the value of an option, this exact same object x ends up as the value of that option after instantiation?

comment:5 Changed 13 years ago by timmolendijk

Resolution: invalid
Status: closedreopened

See previous comment

comment:6 Changed 13 years ago by Scott González

Resolution: invalid
Status: reopenedclosed

No. Deep copying is the intended behavior. Please do not re-open this ticket.

Note: See TracTickets for help on using tickets.