isPlainObject sounds perfect. It evokes "Plain Old JavaScript Object", which
applies equally to {} and 'new Object' but not to 'new Foobar' or a String.

John, sorry I was cranky about this last night, but trust me, it matters.
Any experienced JavaScript programmer will do a double-take on
isObjectLiteral just like I did, thinking, "Huh? That's impossible! What
does the function *really* do?"

The performance of this function may catch people by surprise, though. It's
going to be pretty slow if the object has many properties. It would be
useful if there were a comment in the code indicating *why* it has to have
that for loop that iterates through every property of the object. There's
some commentary about the order of enumeration in that for loop, but I
didn't see anything about why the loop is needed in the first place. (And
whew - talk about undocumented browser behavior! A bit scary...)

Sorry this is a bit OT for this thread... :-)

-Mike

On Wed, Dec 2, 2009 at 6:43 PM, Julian Aubourg <aubourg.jul...@gmail.com>wrote:

> isPlainObject?
>
> Anyway, progress again on the transport front. Transport definition reduced
> to 2 functions (the response headers are now passed to the complete callback
> which is simpler and more elegant). Also, the new architecture didn't
> prevent the infamous memory leak when using onreadystatechange under IE, so
> I re-introduced the setInterval trick.
>
> 2009/12/3 John Resig <jere...@gmail.com>
>
> Well, we don't want "isObject" (or isJavaScriptObject or
>> isNativeObject) since that'll allow things like 'new String'. We
>> explicitly want the case where people are using {} or new Object in
>> their code, adding on some properties, and passing it around. It sound
>> like you're worried about some sort of semantic difference between
>> isObjectLiteral and wasDefinedUsingAnObjectLiteral - but I don't think
>> that really matters.
>>
>> --John
>>
>>
>>
>> On Wed, Dec 2, 2009 at 7:36 PM, Michael Geary <m...@mg.to> wrote:
>> > "isObjectLiteral" is a really poor name for that function. It makes no
>> sense
>> > at all. An object *literal* is text. It's not an object until it's
>> parsed,
>> > and then it's not an object literal any more, it's just an Object.
>> >
>> > Case in point: jQuery.isObjectLiteral({}) and jQuery.isObjectLiteral(new
>> > Object) both return true. I don't think there is any way to distinguish
>> > between a '{}' and a 'new Object', is there?
>> >
>> > This function definitely needs to be renamed. What does it actually do?
>> Is
>> > its purpose to distinguish between a JavaScript object and a DOM object?
>> > Then it could be called isJavaScriptObject or isNativeObject or some
>> such.
>> > Not isObjectLiteral please.
>> >
>> > Sorry, this is one of my pet peeves - the Google Maps API documentation
>> > describes many of its option objects as "object literals", which is
>> quite
>> > misleading and confusing. (Maps newbies sometimes think they *have* to
>> use
>> > an object literal and can't use an object that they build on the fly.)
>> >
>> > -Mike
>>
>

--

You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-...@googlegroups.com.
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en.


Reply via email to