Why use jQuery.isObject in jQuery.extend
|
View:
New views
20 Messages
—
Rating Filter:
Alert me
|
| < Prev | 1 - 2 | Next > |
|
|
Why use jQuery.isObject in jQuery.extendIn the current implementation of jQuery.extend we can find the
following code: // Recurse if we're merging object values if ( deep && copy && typeof copy === "object" && !copy.nodeType ) { var clone; if ( src ) { clone = src; } else if ( jQuery.isArray(copy) ) { clone = []; } else if ( jQuery.isObject(copy) ) { clone = {}; } else { clone = copy; } // Never move original objects, clone them target[ name ] = jQuery.extend( deep, clone, copy ); } If the first test passes, we know that copy is of type object. So what is this jQuery.isObject exactly supposed to test? It's probably meant to be more precise than the first test, excluding objects such as "new Date()". What is strange is that the current implementation of isObject always returns false (and seems therefore useless, as suggested in http://dev.jquery.com/ticket/4946) without causing any test to fail, while replacing its code with function( obj ) { return Object.prototype.toString.call( obj ); } will cause one test to fail (test 10 with custom objects)... Could someone light me up? -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Why use jQuery.isObject in jQuery.extendYehuda was working through that code and didn't get a chance to finish
it up. Yehuda, any thoughts? --John On Sat, Nov 7, 2009 at 12:05 AM, lrbabe <lrbabe@...> wrote: > In the current implementation of jQuery.extend we can find the > following code: > > // Recurse if we're merging object values > if ( deep && copy && typeof copy === "object" && !copy.nodeType ) { > var clone; > > if ( src ) { > clone = src; > } else if ( jQuery.isArray(copy) ) { > clone = []; > } else if ( jQuery.isObject(copy) ) { > clone = {}; > } else { > clone = copy; > } > > // Never move original objects, clone them > target[ name ] = jQuery.extend( deep, clone, copy ); > } > > If the first test passes, we know that copy is of type object. So what > is this jQuery.isObject exactly supposed to test? > It's probably meant to be more precise than the first test, excluding > objects such as "new Date()". What is strange is that the current > implementation of isObject always returns false (and seems therefore > useless, as suggested in http://dev.jquery.com/ticket/4946) without > causing any test to fail, while replacing its code with > function( obj ) { > return Object.prototype.toString.call( obj ); > } > will cause one test to fail (test 10 with custom objects)... > > Could someone light me up? > > -- > > You received this message because you are subscribed to the Google Groups "jQuery Development" group. > To post to this group, send email to jquery-dev@.... > To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... > For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Why use jQuery.isObject in jQuery.extendFor IE, isObject(), is perhaps not that trivial ... DBJ
-- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Why use jQuery.isObject in jQuery.extendMaybe something like http://gist.github.com/229188 would be enough.
On Nov 7, 12:57 am, John Resig <jere...@...> wrote: > Yehuda was working through that code and didn't get a chance to finish > it up. Yehuda, any thoughts? > > --John > > On Sat, Nov 7, 2009 at 12:05 AM, lrbabe <lrb...@...> wrote: > > In the current implementation of jQuery.extend we can find the > > following code: > > > // Recurse if we're merging object values > > if ( deep && copy && typeof copy === "object" && !copy.nodeType ) { > > var clone; > > > if ( src ) { > > clone = src; > > } else if ( jQuery.isArray(copy) ) { > > clone = []; > > } else if ( jQuery.isObject(copy) ) { > > clone = {}; > > } else { > > clone = copy; > > } > > > // Never move original objects, clone them > > target[ name ] = jQuery.extend( deep, clone, copy ); > > } > > > If the first test passes, we know that copy is of type object. So what > > is this jQuery.isObject exactly supposed to test? > > It's probably meant to be more precise than the first test, excluding > > objects such as "new Date()". What is strange is that the current > > implementation of isObject always returns false (and seems therefore > > useless, as suggested inhttp://dev.jquery.com/ticket/4946) without > > causing any test to fail, while replacing its code with > > function( obj ) { > > return Object.prototype.toString.call( obj ); > > } > > will cause one test to fail (test 10 with custom objects)... > > > Could someone light me up? > > > -- > > > You received this message because you are subscribed to the Google Groups "jQuery Development" group. > > To post to this group, send email to jquery-dev@.... > > To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... > > For more options, visit this group athttp://groups.google.com/group/jquery-dev?hl=en. -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Why use jQuery.isObject in jQuery.extendIt's actually not clear where the problem lies, I'll test your code.
On Nov 8, 10:31 am, Robert Katić <robert.ka...@...> wrote: > Maybe something likehttp://gist.github.com/229188would be enough. > > On Nov 7, 12:57 am, John Resig <jere...@...> wrote: > > > Yehuda was working through that code and didn't get a chance to finish > > it up. Yehuda, any thoughts? > > > --John > > > On Sat, Nov 7, 2009 at 12:05 AM, lrbabe <lrb...@...> wrote: > > > In the current implementation of jQuery.extend we can find the > > > following code: > > > > // Recurse if we're merging object values > > > if ( deep && copy && typeof copy === "object" && !copy.nodeType ) { > > > var clone; > > > > if ( src ) { > > > clone = src; > > > } else if ( jQuery.isArray(copy) ) { > > > clone = []; > > > } else if ( jQuery.isObject(copy) ) { > > > clone = {}; > > > } else { > > > clone = copy; > > > } > > > > // Never move original objects, clone them > > > target[ name ] = jQuery.extend( deep, clone, copy ); > > > } > > > > If the first test passes, we know that copy is of type object. So what > > > is this jQuery.isObject exactly supposed to test? > > > It's probably meant to be more precise than the first test, excluding > > > objects such as "new Date()". What is strange is that the current > > > implementation of isObject always returns false (and seems therefore > > > useless, as suggested inhttp://dev.jquery.com/ticket/4946) without > > > causing any test to fail, while replacing its code with > > > function( obj ) { > > > return Object.prototype.toString.call( obj ); > > > } > > > will cause one test to fail (test 10 with custom objects)... > > > > Could someone light me up? > > > > -- > > > > You received this message because you are subscribed to the Google Groups "jQuery Development" group. > > > To post to this group, send email to jquery-dev@.... > > > To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... > > > For more options, visit this group athttp://groups.google.com/group/jquery-dev?hl=en. -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Why use jQuery.isObject in jQuery.extendThis version of isObject, in IE returns true, when tested with
window.alert ... --DBJ -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Why use jQuery.isObject in jQuery.extendNative functions in IE is not handled correctly by isFunction either,
but it was decided that that cases are not significant... On Nov 8, 12:23 pm, DBJDBJ <dbj...@...> wrote: > This version of isObject, in IE returns true, when tested with > window.alert ... > > --DBJ -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Re: Why use jQuery.isObject in jQuery.extendIn case everyone missed it - this discussion happened a few months ago
where we debated what exactly a good solution would look like: http://gist.github.com/153271 Right now the: return /^function Object/.test( obj.constructor ); solution works the best but it doesn't work in Opera Mini (which doesn't have function decompilation) - nor is it particularly fast. As I remember it, when we left off working on that function we were trying to find a better solution. --John On Sun, Nov 8, 2009 at 12:29 PM, Robert Katić <robert.katic@...> wrote: > Native functions in IE is not handled correctly by isFunction either, > but it was decided that that cases are not significant... > > On Nov 8, 12:23 pm, DBJDBJ <dbj...@...> wrote: >> This version of isObject, in IE returns true, when tested with >> window.alert ... >> >> --DBJ > > -- > > You received this message because you are subscribed to the Google Groups "jQuery Development" group. > To post to this group, send email to jquery-dev@.... > To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... > For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Why use jQuery.isObject in jQuery.extend> Right now the:
> return /^function Object/.test( obj.constructor ); > > solution works the best but it doesn't work in Opera Mini (which > doesn't have function decompilation) - nor is it particularly fast. constructor property is often changed. I hope you want isObject(jQuery()) == false. -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Re: Why use jQuery.isObject in jQuery.extend> constructor property is often changed.
> I hope you want isObject(jQuery()) == false. Yep, and that'll work as we expect it to. The one case where it won't is if you do obj.constructor = Object; If anyone thinks of an alternative solution please feel free to modify the gist and put your code up there - something that covers all the test cases would be great. --John -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Why use jQuery.isObject in jQuery.extend/^function Object/.test( jQuery().constructor ) == true
You don't need to explicitly set constructor to change it. Redefining prototype, constructor is automatically altered (==Object). On Nov 8, 2:13 pm, John Resig <jere...@...> wrote: > > constructor property is often changed. > > I hope you want isObject(jQuery()) == false. > > Yep, and that'll work as we expect it to. The one case where it won't > is if you do obj.constructor = Object; > > If anyone thinks of an alternative solution please feel free to modify > the gist and put your code up there - something that covers all the > test cases would be great. > > --John -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Why use jQuery.isObject in jQuery.extendhttp://gist.github.com/229254
On Nov 8, 2:13 pm, John Resig <jere...@...> wrote: > > constructor property is often changed. > > I hope you want isObject(jQuery()) == false. > > Yep, and that'll work as we expect it to. The one case where it won't > is if you do obj.constructor = Object; > > If anyone thinks of an alternative solution please feel free to modify > the gist and put your code up there - something that covers all the > test cases would be great. > > --John -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Re: Why use jQuery.isObject in jQuery.extend> http://gist.github.com/229254
Does this handle all the tests on that page? and in IE 6/7/8 as well? If so, let's land it. --John -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Why use jQuery.isObject in jQuery.extendI thing so, but not sure 100%. This seam a good task for TestSwarms.
On Nov 8, 4:38 pm, John Resig <jere...@...> wrote: > >http://gist.github.com/229254 > > Does this handle all the tests on that page? and in IE 6/7/8 as well? > > If so, let's land it. > > --John -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Why use jQuery.isObject in jQuery.extendhttp://browsershots.org/http://bender.fesb.hr/~robert/scripts/isObjectLiteral.html
Let's see... On Nov 8, 4:42 pm, Robert Katić <robert.ka...@...> wrote: > I thing so, but not sure 100%. This seam a good task for TestSwarms. > > On Nov 8, 4:38 pm, John Resig <jere...@...> wrote: > > > >http://gist.github.com/229254 > > > Does this handle all the tests on that page? and in IE 6/7/8 as well? > > > If so, let's land it. > > > --John -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Re: Why use jQuery.isObject in jQuery.extend> I thing so, but not sure 100%. This seam a good task for TestSwarms.
Well, we can do that eventually - but in the short term: Does it work on IE? --John -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Why use jQuery.isObject in jQuery.extendYes, it passes all these tests.
On Nov 8, 4:57 pm, John Resig <jere...@...> wrote: > > I thing so, but not sure 100%. This seam a good task for TestSwarms. > > Well, we can do that eventually - but in the short term: Does it work on IE? > > --John -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Re: Why use jQuery.isObject in jQuery.extendNice! Just make a bug and link to your commit on your Github fork and
I'll land it (also, be sure to get the spacing right - and be sure to use {} braces and ===). --John On Sun, Nov 8, 2009 at 5:19 PM, Robert Katić <robert.katic@...> wrote: > Yes, it passes all these tests. > > On Nov 8, 4:57 pm, John Resig <jere...@...> wrote: >> > I thing so, but not sure 100%. This seam a good task for TestSwarms. >> >> Well, we can do that eventually - but in the short term: Does it work on IE? >> >> --John > > -- > > You received this message because you are subscribed to the Google Groups "jQuery Development" group. > To post to this group, send email to jquery-dev@.... > To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... > For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Why use jQuery.isObject in jQuery.extendhttp://dev.jquery.com/ticket/5474
On Nov 8, 2:13 pm, John Resig <jere...@...> wrote: > > constructor property is often changed. > > I hope you want isObject(jQuery()) == false. > > Yep, and that'll work as we expect it to. The one case where it won't > is if you do obj.constructor = Object; > > If anyone thinks of an alternative solution please feel free to modify > the gist and put your code up there - something that covers all the > test cases would be great. > > --John -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
|
|
Re: Why use jQuery.isObject in jQuery.extendThanks!
On Sunday, November 8, 2009, Robert Katić <robert.katic@...> wrote: > http://dev.jquery.com/ticket/5474 > > On Nov 8, 2:13 pm, John Resig <jere...@...> wrote: >> > constructor property is often changed. >> > I hope you want isObject(jQuery()) == false. >> >> Yep, and that'll work as we expect it to. The one case where it won't >> is if you do obj.constructor = Object; >> >> If anyone thinks of an alternative solution please feel free to modify >> the gist and put your code up there - something that covers all the >> test cases would be great. >> >> --John > > -- > > You received this message because you are subscribed to the Google Groups "jQuery Development" group. > To post to this group, send email to jquery-dev@.... > To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... > For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. > > > -- --John -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@.... To unsubscribe from this group, send email to jquery-dev+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en. |
| < Prev | 1 - 2 | Next > |
| Free embeddable forum powered by Nabble | Forum Help |