Open scien opened 10 years ago
jquery deep extend can't be used directly.
$.extend(true, [1, 2, 3, 4, 5, 6], [7, 8, 9])
[7, 8, 9, 4, 5, 6]
I was unaware this was how jquery treated arrays in deep merges. very good to know. a shallow merge would replace the array as expected, but then my custom settings would replace the entire units
section of the options which causes a ton of other issues. ex: o.units.hour.am[0]
- can't read property am of undefined
Hey @scien .. yeah the issue with $.extend is why I created the built in extend to try and get around that. Seems to be a fine balance to merge objects but replace arrays completely. Were you able to resolve your issue? Thanks for digging in to the code.
This doesn't work. Instead you get all 40 default options. The issue is with the
extend
function.This sometimes sets
o1[p] = o2[p]
wheno2[p]
is an object (it sets the reference). This causes data to be mixed from$.intimidatetime.i18n['']
,$.intimidatetime.defaults
, and my custom options. and the custom options end up getting overwritten by the Array[40] default.The stack/flow looks like goes...
$h = $('<div class="'+s.theme+'-range '+s.theme+'-range-'+i+'"><div class="'+s.theme+'-preview">'+ $.intimidatetime.dateFormat(s.value[i], s.previewFormat, s) +'</div></div>').appendTo(inst.$p);
in refresh. which calls dateFormat$.intimidatetime.extend({},$.intimidatetime.i18n[''], $.intimidatetime.defaults, options || {})
and then my original options have been overwritten.
As a quick fix, I updated my local extend function to the following...
I'm going to pull out the Zepto code and just use $.extend and see if that works