Javascript library development

P

Peter Michaux

Jorge meinte:
Still, what's your point?

That yes, that string concatenation (even when fed with string
object(s)) yields string primitive values not string objects.

Try with "string".concat("string") and ["string"].join("string"), and
the results are the same :

javascript:alert(typeof (new String("Hola")).concat(""));
--> string.

javascript:alert(typeof [new String("Hola")].join(""));
--> string.

Just out of curiosity, since you are using the javascript protocol for
testing, do you know about the console in the Firebug extension for
Firefox?
Still, Resig is right in the sense that a there's no way to modify a
string object. Or not ?

You can modify a String object at least in the sense you can add
properties to it.

var s = new String("Hola");

alert(s.doAlert) ; undefined

s.doAlert = function() {
alert(this);
};

alert(s.doAlert) ; function()...

s.doAlert() ; makes an alert "Hola"

Peter
 
J

Jorge

(...)

( ) Your not understanding what a String object is.

(It is a radio button group. Choose one.)

(...)

IOW, John Resig does not know what he is writing about (there).
Hopefully, you will begin to as of now.

( ) You forgot to take today's medication.
( ) You ran out of pills.

(It is a radio button group. Choose one.)

:)

Regards,
--Jorge.
 
J

Jorge

That yes, that string concatenation (even when fed with string
object(s)) yields string primitive values not string objects.
Try with "string".concat("string") and ["string"].join("string"), and
the results are the same :
javascript:alert(typeof (new String("Hola")).concat(""));
--> string.
javascript:alert(typeof [new String("Hola")].join(""));
--> string.

Just out of curiosity, since you are using the javascript protocol for
testing, do you know about the console in the Firebug extension for
Firefox?
Still, Resig is right in the sense that a there's no way to modify a
string object. Or not ?

You can modify a String object at least in the sense you can add
properties to it.

Ok. Let's say that "there's no way to change the string in a string
object". (?)

--Jorge.
 
R

Richard Cornford

It is certainly the case that the statement about concatenation would
not have had to be very different in its wording in order to have been a
true statement about javascript (unlike some of the others which are
just wrong in every single detail).

But the significant aspect of that quote is what is revealed by the
error that it does contain. You will notice that the participants in
this group cover pretty much the whole spectrum of javascript knowledge,
form total novices (usually in the role of people asking for help)
though to people who have learnt enough to see aspects of the language
that its authors have (or would prefer to have) forgotten. Participate
for long enough and patterns start to emerge in terms of misconceptions
about the langue, and how those misconceptions relate to an individuals
positions along the javascript learning curve.

Misconceptions about the distinction between primitive values and object
values are very common among beginners. And people who come to
javascript from Java (especially, but not exclusively) have a strong
tendency to assume that javascript strings will be string object (as
they are in Java). The implications of that misconception are not that
great, but it still should be corrected (and here it is corrected on a
fairly regular basis). (Someone here corrected that misconception for me
back in 2002).

There is another pattern to be observed here; that superficial success
(often in the form of first managing to create something that works in
more than two browsers) results in massive overconfidence. The belief
that you have cracked the problem, seen the truth, learnt everything of
importance and entered the inner circle. It is a dangerous phenomenon,
partly because it encourages people to go out and do things that may not
be such a good idea in retrospect, and partly because confidence that
you already know everything can be a huge barrier to learning more
(and/or recognising that you may be wrong).

It is sometimes necessary to slap someone pretty hard to get them out of
that state. The person here who did that to me back in 2002 probably did
me one of the biggest favours I have ever received, even if I could not
properly appreciate that at the time.
Ok. Let's say that "there's no way to change the string
in a string object". (?)

That certainly should not be a point being made in relation to
concatenation operations because in concatenation any non-string
primitive operands are type-converted into string primitives.

The truth is that javascript has no operations that are capable of
changing the value of any of its 5 primitives types. In the absence of
an operation that could chagne a primitive value primitive values must
be unchangeable (at least from the perspective of anyone programming
javascript).

Richard.
 
M

Mike Duffy

Jorge wrote:

There is another pattern to be observed here; that superficial success
(...) results in massive overconfidence. The belief
that you have cracked the problem, seen the truth, learnt everything of
importance and entered the inner circle. It is a dangerous phenomenon,
partly because it encourages people to go out and do things that may not
be such a good idea in retrospect, and partly because confidence that
you already know everything can be a huge barrier to learning more
(and/or recognising that you may be wrong).

This can be said about almost any discipline. It may be though, that
programming languages make the mistakes more obvious, much in the same way
that it is impossible to proof-read your own prose.

Also, when you only see the final product, it is not obvious how much time
was spent exploring dead-end paths. (Also called "hands-on" learning.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,191
Latest member
BuyKetoBeez

Latest Threads

Top