<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>The JScript Type System, Part Two: Prototypes and constructors</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx</link><description>In today's installment, things get complicated.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>RE: The JScript Type System, Part Two: Prototypes and constructors</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx#53353</link><pubDate>Thu, 06 Nov 2003 22:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:53353</guid><dc:creator>Erik Arvidsson</dc:creator><description>Just a side note. The prototype object is usually called  __proto__ ( [[Protoype]] in the spec) and almost all ECMAScript engines (except the Microsoft ones) allows read write of this private property.</description></item><item><title>RE: The JScript Type System, Part Two: Prototypes and constructors</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx#53356</link><pubDate>Fri, 07 Nov 2003 02:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:53356</guid><dc:creator>Jay Hugard</dc:creator><description>Can you explain the logic behind the following madness (in JScript Classic), which appears to mean that a string is not always a String but a regexp is always a RegExp?

Conversly, what is the recommended way of determining if a value is a string?

slit instanceof String =&amp;gt; false
sobj instanceof String =&amp;gt; true
slit instanceof Object =&amp;gt; false
sobj instanceof Object =&amp;gt; true
typeof( slit ) =&amp;gt; string
typeof( sobj ) =&amp;gt; object
typeof( slit ) == typeof( sobj ) =&amp;gt; false

relit instanceof RegExp =&amp;gt; true
reobj instanceof RegExp =&amp;gt; true
relit instanceof Object =&amp;gt; true
reobj instanceof Object =&amp;gt; true
typeof( relit ) =&amp;gt; object
typeof( reobj ) =&amp;gt; object
typeof( relit ) == typeof( reobj ) =&amp;gt; true

As generated by:

function println(s) { WScript.echo(s) /*System.Console.Out.WriteLine(s)*/ }

function evalprintln( s )
{
	if( !s ) { println(&amp;quot;&amp;quot;); return }
	var out = s + &amp;quot; =&amp;gt; &amp;quot;;
	try{ out += eval(s) } catch( e ) { out += &amp;quot;Error: &amp;quot; + e.description }
	println(out);
}

var slit = &amp;quot;Literal String&amp;quot;;
var sobj = new String( &amp;quot;String object&amp;quot; );
var relit = /literal regexp/i
var reobj = new RegExp( &amp;quot;RegExp object&amp;quot; );

var tests = [
	&amp;quot;slit instanceof String&amp;quot;,
	&amp;quot;sobj instanceof String&amp;quot;,
	&amp;quot;slit instanceof Object&amp;quot;,
	&amp;quot;sobj instanceof Object&amp;quot;,
	&amp;quot;typeof( slit )&amp;quot;,
	&amp;quot;typeof( sobj )&amp;quot;,
	&amp;quot;typeof( slit ) == typeof( sobj )&amp;quot;,
	null,
	&amp;quot;relit instanceof RegExp&amp;quot;,
	&amp;quot;reobj instanceof RegExp&amp;quot;,
	&amp;quot;relit instanceof Object&amp;quot;,
	&amp;quot;reobj instanceof Object&amp;quot;,
	&amp;quot;typeof( relit )&amp;quot;,
	&amp;quot;typeof( reobj )&amp;quot;,
	&amp;quot;typeof( relit ) == typeof( reobj )&amp;quot;
	];
	
for( var ix in tests ) { evalprintln( tests[ix] ) }
</description></item><item><title>RE: The JScript Type System, Part Two: Prototypes and constructors</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx#53357</link><pubDate>Fri, 07 Nov 2003 02:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:53357</guid><dc:creator>Peter Torr</dc:creator><description>Erik -- IIRC, Netscape removed the support for __proto__ from their engine some years ago because it was a bad idea to let people mess with the prototype chain this way. The ECMA standard does not require the property to be exposed, and it is dangerous to do so.</description></item><item><title>RE: The JScript Type System, Part Two: Prototypes and constructors</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx#53358</link><pubDate>Fri, 07 Nov 2003 02:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:53358</guid><dc:creator>Peter Torr</dc:creator><description>Jay, if you read the ECMA spec you will see that there are string primitives and string objects, just as there are number/boolean primitives and number/boolean objects. Basically you should never use &amp;quot;new String(...)&amp;quot; because it is a waste of time and energy.

var nlit = 42
var nobj = new Number(42)

print(nlit instanceof Number)
print(nlit instanceof Object)
print(nobj instanceof Number)
print(nobj instanceof Object)


</description></item><item><title>RE: The JScript Type System, Part Two: Prototypes and constructors</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx#53359</link><pubDate>Fri, 07 Nov 2003 10:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:53359</guid><dc:creator>IUnknown</dc:creator><description>&amp;gt;JScript, unlike VBScript, does not interrogate COM objects to determine &amp;gt;the class name. 

This gets the award for the most unrelated error message:
TypeName(myObject)
throws, when the type information is unavailable:
Out Of string space: 'TypeName'</description></item><item><title>RE: The JScript Type System, Part Two: Prototypes and constructors</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx#53360</link><pubDate>Fri, 07 Nov 2003 20:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:53360</guid><dc:creator>Eric Lippert</dc:creator><description>Can I see a repro for that?  If the type name is unavailable, it should return &amp;quot;Unknown&amp;quot; or, if it is an IDispatch, &amp;quot;Object&amp;quot;.  

TypeName does return &amp;quot;Out of string space&amp;quot;, but only when the attempt to allocate the string for the type name fails.</description></item><item><title>RE: The JScript Type System, Part Two: Prototypes and constructors</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx#53361</link><pubDate>Fri, 07 Nov 2003 23:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:53361</guid><dc:creator>Erik Arvidsson</dc:creator><description>Peter: I know both the Mozilla engines (C and Java) and the Macromedia engine has support for this. I was pretty sure that Opera supported this as well but I just verifed that they do not.

I can understand why it is considered dangerous but usage of __proto__ can be very useful. For example it allows you to skip creating an instance that is used as the prototype.

fucntion SubClass( args )
{
   SuperClass.call( args );
}
SubClass.prototype.__proto__ = SuperClass.prototype;

Well, well... now that we have ECMAScript v4 around the corner there is no real need for this.</description></item><item><title>RE: The JScript Type System, Part Two: Prototypes and constructors</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx#53362</link><pubDate>Sat, 08 Nov 2003 01:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:53362</guid><dc:creator>Eric Lippert</dc:creator><description>&amp;gt; Well, well... now that we have ECMAScript v4 around the corner there is no real need for this.

That's news to me.  Could you more precisely define &amp;quot;around the corner&amp;quot;? </description></item><item><title>RE: The JScript Type System, Part Two: Prototypes and constructors</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx#53363</link><pubDate>Sat, 08 Nov 2003 01:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:53363</guid><dc:creator>Isaac</dc:creator><description>&amp;gt; conflated static typing with strong typing
&amp;quot;static typing&amp;quot; unhelpfully confuses when checks are made with the kind of checks that are made.

Simpler to understand that C++ is a statically-checked weakly-typed language (and also that some things are dynamically checked in C++).

Simpler to understand that JScript is a dynamically-checked untyped (safe?) language. 

I think you demonstrated that it's pretty hard to figure out what the type of a value is in JScript - so why insist on calling it a typed language?</description></item><item><title>RE: The JScript Type System, Part Two: Prototypes and constructors</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx#53364</link><pubDate>Sat, 08 Nov 2003 14:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:53364</guid><dc:creator>Anonymous</dc:creator><description>[quote]Can I see a repro for that? If the type name is unavailable, it should return &amp;quot;Unknown&amp;quot; or, if it is an IDispatch, &amp;quot;Object&amp;quot;. [/quote]

I got this when trying it on a COM object that uses run-time generated type info (ie. CreateDispTypeInfo). This only provides a minimal implementation of ITypeInfo. This is not common(or recommended) so I wouldn't worry too much. If it helps the COM object is out of process.

Also see this:
http://groups.google.com/groups?q=typeName+%22Out+of+string+space%22</description></item><item><title>RE: The JScript Type System, Part Two: Prototypes and constructors</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx#53365</link><pubDate>Sat, 08 Nov 2003 18:57:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:53365</guid><dc:creator>Eric Lippert</dc:creator><description>OK, then I have a guess as to what is happening.  This is a TERRIBLE way to wait for an out-of-proc object (OOPO) to shut down.  I'll bet that there is a race condition here where the stub is returning a pointer to memory that becomes bad when the OOPO shuts down.  So the TypeName method essentially gets passed a pointer to bad memory.

Now suppose that the bad memory happens to be in a readable committed page, but contains garbage.  We assume that the thing is a BSTR, so we look at the value stashed preceding the string body to determine the length.  That could be any old number; the odds that the number happens to be larger than the largest remaining heap block are actually very good.

So what we've got here is a memory corruption bug that is not crashing, but returning a bogus error instead.</description></item><item><title>RE: The JScript Type System, Part Two: Prototypes and constructors</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx#53366</link><pubDate>Sun, 09 Nov 2003 12:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:53366</guid><dc:creator>Anonymous</dc:creator><description>The link I posted was just something I found while searching on the error. My situation relates to using run time type info. Have you tested TypeName with run time type info? It is obsolete and I only use it for testing so this discussion is essentially accademic.

My guess is that something similar is happening, ITypeInfo must be returning bogus data. Assuming that you check all error results this could even be a bug in the implementation of ITypeInfo for CreateDispTypeInfo. As mentioned, this is obsolete and probably hasn't been looked at for a long time.

I think my object was based on the code found here, so if you want to copy and paste:
http://docs.rinet.ru:8083/VidimyyC/vcu28fi.htm#I25</description></item><item><title>re: The JScript Type System, Part Two: Prototypes and constructors</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx#124705</link><pubDate>Sun, 02 May 2004 14:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:124705</guid><dc:creator>Erik Arvidsson</dc:creator><description>&amp;quot;That's news to me. Could you more precisely define &amp;quot;around the corner&amp;quot;?&amp;quot;&lt;br&gt;&lt;br&gt;I guess I was wrong :'( This has been in the works for way too long...&lt;br&gt;&lt;br&gt;Known implemantions of ECMAScript v4:&lt;br&gt;&lt;br&gt;ActionScript&lt;br&gt;QTScript&lt;br&gt;JScript 7&lt;br&gt;&lt;br&gt;One possible reason for JS2 taking so long might be that ECMA moved all their resources to C# instead?</description></item><item><title>re: The JScript Type System, Part Two: Prototypes and constructors</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx#124715</link><pubDate>Sun, 02 May 2004 15:23:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:124715</guid><dc:creator>Eric Lippert</dc:creator><description>A more likely reason is that Waldemar Horwat, who was the primary driving force behind the E4 spec, no longer works for AOL-Time-Warner-Netscape and hence is no longer being paid to drive the spec process forward.  (Rumour has it that he's at google now.)  &lt;br&gt;&lt;br&gt;Microsoft is still involved in the E4 process, but it is slow going.</description></item><item><title>Wherefore IDispatchEx?</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx#239293</link><pubDate>Thu, 07 Oct 2004 20:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:239293</guid><dc:creator>Fabulous Adventures In Coding</dc:creator><description /></item><item><title>Intercept instanceof | keyongtech</title><link>http://blogs.msdn.com/ericlippert/archive/2003/11/06/53352.aspx#9338455</link><pubDate>Sun, 18 Jan 2009 20:41:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9338455</guid><dc:creator>Intercept instanceof | keyongtech</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.keyongtech.com/4947719-intercept-instanceof"&gt;http://www.keyongtech.com/4947719-intercept-instanceof&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>