Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #8586
| From | "J.R." <groups_jr-1@yahoo.com.br> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Language Confusions |
| Date | 2011-11-24 00:07 -0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <jak8te$tml$1@speranza.aioe.org> (permalink) |
| References | <as6rc7h1tvnihohthiop2vetdkhnddmv5q@4ax.com> |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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