Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #8586

Re: Language Confusions

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail
From "J.R." <groups_jr-1@yahoo.com.br>
Newsgroups comp.lang.javascript
Subject Re: Language Confusions
Date Thu, 24 Nov 2011 00:07:46 -0200
Organization Aioe.org NNTP Server
Lines 48
Message-ID <jak8te$tml$1@speranza.aioe.org> (permalink)
References <as6rc7h1tvnihohthiop2vetdkhnddmv5q@4ax.com>
NNTP-Posting-Host edb3lPNLwDIT/BKKc/Xuzw.user.speranza.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
User-Agent Mozilla/5.0 (Windows NT 6.0; rv:8.0) Gecko/20111105 Thunderbird/8.0
X-Antivirus-Status Clean
X-Notice Filtered by postfilter v. 0.8.2
X-Antivirus avast! (VPS 111123-2, 11/23/2011), Outbound message
Xref x330-a1.tempe.blueboxinc.net comp.lang.javascript:8586

Show key headers only | View raw


On 23/11/2011 23:38, Gene Wirchenko wrote:
> Dear JavaScripters:
>
>       I have been carefully studying JavaScript and have learned a lot
> more than I ever knew about it.  I have some questions about niggling
> points:
>
>    1) What is the difference between:
>            s="Hello";
>            s=new String("Hello");
>            s=String("Hello");
> The text I am studying says that the first two are the same.  Fine.
> The third behaves the same way AFAICS.  Could someone please
> illustrate the difference?
>

If you paste the following code snippet in a JavaScript console such as 
Firebug's (in Firefox), you will notice the difference:

   var s1 = "Hello",
       s2 = new String("Hello"),
       s3 = String("Hello");

   console.log(typeof s1); // "string"
   console.log(typeof s2); // "object"
   console.log(typeof s3); // "string"

So "the first two are the same" is wrong... Check the ECMAScript 
Language Specification to learn the why's.

>    2) I am unclear on exactly all what .prototype does.  For adding
> methods to an object type, fine.  In the text that I am studying,
> there is an example of a table object.  The author then shows how to
> add a method to an object type (without modifying the base code), and
> how it is done has me puzzled:
>            function table_colorWrite(doc)
>               body omitted
> followed by
>            table.prototype.colorWrite=table_colorWrite
> I am not clear on what .prototype does in this line.  I think I must
> be missing something about the JavaScript object model.

An explanation about prototype in JavaScript would require a lot of 
typing here... So I'd suggest a further reading at 
<http://javascript.crockford.com/prototypal.html>

-- 
Joao Rodrigues (J.R.)

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Language Confusions Gene Wirchenko <genew@ocis.net> - 2011-11-23 17:38 -0800
  Re: Language Confusions "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-24 00:07 -0200
  Re: Language Confusions Richard Cornford <Richard@litotes.demon.co.uk> - 2011-11-24 05:41 -0800
    Re: Language Confusions Gene Wirchenko <genew@ocis.net> - 2011-11-24 11:27 -0800

csiph-web