<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.1" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Just what is this Javascript object you handed me?</title>
	<link>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/</link>
	<description>A lot of the time I hear ducks</description>
	<pubDate>Wed, 03 Dec 2008 21:00:35 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>

	<item>
		<title>By: The BigDingus Blogger</title>
		<link>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-2770</link>
		<author>The BigDingus Blogger</author>
		<pubDate>Tue, 23 Sep 2008 16:11:19 +0000</pubDate>
		<guid>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-2770</guid>
		<description>Well "typeof" isn't too useful because it doesn't tell me much about my constructor.

It's been a couple months since I wrote this blog post. Since then, I've started to think a couple of things:

*) Multi-frame applications are perilous

*) Passing between frames may best be done by explicit serialization (to JSON for example), though that's a big pain with simple things like Date objects</description>
		<content:encoded><![CDATA[<p>Well &#8220;typeof&#8221; isn&#8217;t too useful because it doesn&#8217;t tell me much about my constructor.</p>
<p>It&#8217;s been a couple months since I wrote this blog post. Since then, I&#8217;ve started to think a couple of things:</p>
<p>*) Multi-frame applications are perilous</p>
<p>*) Passing between frames may best be done by explicit serialization (to JSON for example), though that&#8217;s a big pain with simple things like Date objects</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michel</title>
		<link>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-2769</link>
		<author>Michel</author>
		<pubDate>Tue, 23 Sep 2008 15:17:46 +0000</pubDate>
		<guid>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-2769</guid>
		<description>Look for errors in a script, probably to a value or a variable attributed, often helps the temporary use of the typeof operator to type a value or a variable (or an object) to determine.</description>
		<content:encoded><![CDATA[<p>Look for errors in a script, probably to a value or a variable attributed, often helps the temporary use of the typeof operator to type a value or a variable (or an object) to determine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ates Goral</title>
		<link>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-1560</link>
		<author>Ates Goral</author>
		<pubDate>Mon, 11 Aug 2008 16:59:08 +0000</pubDate>
		<guid>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-1560</guid>
		<description>Utility function to find out the actual class names of objects:

http://magnetiq.com/2006/07/10/finding-out-class-names-of-javascript-objects/

It doesn't work for intrinsic objects (like window, document etc.) and just returns undefined.</description>
		<content:encoded><![CDATA[<p>Utility function to find out the actual class names of objects:</p>
<p><a href="http://magnetiq.com/2006/07/10/finding-out-class-names-of-javascript-objects/" rel="nofollow">http://magnetiq.com/2006/07/10/finding-out-class-names-of-javascript-objects/</a></p>
<p>It doesn&#8217;t work for intrinsic objects (like window, document etc.) and just returns undefined.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous Coward</title>
		<link>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-1430</link>
		<author>Anonymous Coward</author>
		<pubDate>Mon, 28 Jul 2008 19:13:42 +0000</pubDate>
		<guid>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-1430</guid>
		<description>@Chad:
I really don't think you should feel any better with typeof value === 'object' instead of typeof value == 'object', because typeof is guaranteed to return a string, while the left hand side is obviously also a string, so a type mismatch is pretty much impossible here.</description>
		<content:encoded><![CDATA[<p>@Chad:<br />
I really don&#8217;t think you should feel any better with typeof value === &#8216;object&#8217; instead of typeof value == &#8216;object&#8217;, because typeof is guaranteed to return a string, while the left hand side is obviously also a string, so a type mismatch is pretty much impossible here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paddy3118</title>
		<link>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-1156</link>
		<author>Paddy3118</author>
		<pubDate>Tue, 24 Jun 2008 15:23:29 +0000</pubDate>
		<guid>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-1156</guid>
		<description>Hi,
The Duck Typing way to solve this is to use the object as if it were an array and catch tne exception if it is not then if it triggers the "I'm not sufficiently an Array" exception, use it as a scaler.

- Paddy.</description>
		<content:encoded><![CDATA[<p>Hi,<br />
The Duck Typing way to solve this is to use the object as if it were an array and catch tne exception if it is not then if it triggers the &#8220;I&#8217;m not sufficiently an Array&#8221; exception, use it as a scaler.</p>
<p>- Paddy.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chad</title>
		<link>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-883</link>
		<author>Chad</author>
		<pubDate>Wed, 23 Apr 2008 02:03:01 +0000</pubDate>
		<guid>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-883</guid>
		<description>I would feel better with:

typeof value === 'object'</description>
		<content:encoded><![CDATA[<p>I would feel better with:</p>
<p>typeof value === &#8216;object&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Trenda</title>
		<link>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-563</link>
		<author>Scott Trenda</author>
		<pubDate>Wed, 09 Jan 2008 03:47:39 +0000</pubDate>
		<guid>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-563</guid>
		<description>I came across this a few days ago, when writing the cross-window functions for a notification-window (essentially a non-blocking alert) system for our UI. My setup was slightly different - the user can specify which window they want the notification to appear in, and the framework ensures that any wrapper window will have the new notify() function (inside of which I needed to do this check) defined on it. I basically needed to see if ContainerWindow.notify == window.self.notify... but that's the same issue you're discussing here - Javascript considers different windows' instances of functions from identical sources to be unique functions.

My solution, and it may have its shortcomings in the long run, was simply to compare the string-values of the functions, instead of the functions themselves. (i.e. String(ContainerWindow.notify) == String(window.self.notify) ) It worked like a charm. That may help here, as native functions could be considered to be unmodifiable without their source appearing in its string-value, at which point string-comparison would return false. The only thing I see that the string values don't take into account is closures/scope. While I think that the situation where two constructors' closures/scope would render them identical in string-value (while the intent of the developer is for them to be recognized as unique constructors) would seldom occur, I'll leave it up for real-world abuse for a while, before I'm convinced either way. ;)</description>
		<content:encoded><![CDATA[<p>I came across this a few days ago, when writing the cross-window functions for a notification-window (essentially a non-blocking alert) system for our UI. My setup was slightly different - the user can specify which window they want the notification to appear in, and the framework ensures that any wrapper window will have the new notify() function (inside of which I needed to do this check) defined on it. I basically needed to see if ContainerWindow.notify == window.self.notify&#8230; but that&#8217;s the same issue you&#8217;re discussing here - Javascript considers different windows&#8217; instances of functions from identical sources to be unique functions.</p>
<p>My solution, and it may have its shortcomings in the long run, was simply to compare the string-values of the functions, instead of the functions themselves. (i.e. String(ContainerWindow.notify) == String(window.self.notify) ) It worked like a charm. That may help here, as native functions could be considered to be unmodifiable without their source appearing in its string-value, at which point string-comparison would return false. The only thing I see that the string values don&#8217;t take into account is closures/scope. While I think that the situation where two constructors&#8217; closures/scope would render them identical in string-value (while the intent of the developer is for them to be recognized as unique constructors) would seldom occur, I&#8217;ll leave it up for real-world abuse for a while, before I&#8217;m convinced either way. <img src='http://bigdingus.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: grey</title>
		<link>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-527</link>
		<author>grey</author>
		<pubDate>Thu, 27 Dec 2007 02:34:41 +0000</pubDate>
		<guid>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-527</guid>
		<description>@Nathar Leichoz:
Someone correct me if I'm wrong, but couldn't this be solved by using the "ownerDocument" property of the passed Node to determine the containing document and go from there? So this is a fixable problem, yes? ;)</description>
		<content:encoded><![CDATA[<p>@Nathar Leichoz:<br />
Someone correct me if I&#8217;m wrong, but couldn&#8217;t this be solved by using the &#8220;ownerDocument&#8221; property of the passed Node to determine the containing document and go from there? So this is a fixable problem, yes? <img src='http://bigdingus.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Danilo Celic</title>
		<link>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-520</link>
		<author>Danilo Celic</author>
		<pubDate>Fri, 21 Dec 2007 15:40:27 +0000</pubDate>
		<guid>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-520</guid>
		<description>Hey Mark,

Thanks for that, I guess I was thinking along the lines of the value.constructor == Function for that check, but I stepped right over typeof when thinking about this. Thanks for the reminder Mark and BigDingus.</description>
		<content:encoded><![CDATA[<p>Hey Mark,</p>
<p>Thanks for that, I guess I was thinking along the lines of the value.constructor == Function for that check, but I stepped right over typeof when thinking about this. Thanks for the reminder Mark and BigDingus.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nathar Leichoz</title>
		<link>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-518</link>
		<author>Nathar Leichoz</author>
		<pubDate>Fri, 21 Dec 2007 14:07:38 +0000</pubDate>
		<guid>http://bigdingus.com/2007/12/08/just-what-is-this-javascript-object-you-handed-me/#comment-518</guid>
		<description>JavaScript libraries in fact suffer a fate much larger than that when used in a multi-framed environment. Any of the following tasks won't work cross frame:

1) Creating elements using convenience functions. e.g.,
jQuery("").appendTo(frames[0].document.body);

2) Getting the style of an element. e.g.,
dojo.style(frames[0].document.body, "color");
because it calls "document.defaultView.getComputedStyle" which is not the same document as the frame's object.

3) Getting the event in IE. e.g.,
Element.observe(frames[0].document.body, f.bindAsEventListener(this));
because it returns window.event instead of frames[0].event;</description>
		<content:encoded><![CDATA[<p>JavaScript libraries in fact suffer a fate much larger than that when used in a multi-framed environment. Any of the following tasks won&#8217;t work cross frame:</p>
<p>1) Creating elements using convenience functions. e.g.,<br />
jQuery(&#8221;").appendTo(frames[0].document.body);</p>
<p>2) Getting the style of an element. e.g.,<br />
dojo.style(frames[0].document.body, &#8220;color&#8221;);<br />
because it calls &#8220;document.defaultView.getComputedStyle&#8221; which is not the same document as the frame&#8217;s object.</p>
<p>3) Getting the event in IE. e.g.,<br />
Element.observe(frames[0].document.body, f.bindAsEventListener(this));<br />
because it returns window.event instead of frames[0].event;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
