to learn jQuery if already using prototype

J

J.S.Criptoff

While c.l.j regulars are ridiculing John Resig's first javascript book
he's writing the second one - "Secrets of the JavaScript Ninja". He
was a javascript Guru. Now he is a javascript Ninja. Hey, it's time to
iconize him!

Your are invited to pray here:
http://ejohn.org/blog/state-of-the-secrets/
 
T

Thomas 'PointedEars' Lahn

J.S.Criptoff said:
While c.l.j regulars are ridiculing John Resig's first javascript book

It does not need to be ridiculed. Many (if not most) of Resig's statements
are provably factually utterly wrong (and have been proven so here), so it
provides the ridiculousness by itself already.
he's writing the second one - "Secrets of the JavaScript Ninja".

OMG!


PointedEars
 
G

Gregor Kofler

J.S.Criptoff meinte:
While c.l.j regulars are ridiculing John Resig's first javascript book
he's writing the second one - "Secrets of the JavaScript Ninja". He
was a javascript Guru. Now he is a javascript Ninja. Hey, it's time to
iconize him!

I thought he was an "evangelist". Anyway, "What does with(){...} do and
why is it so useful?" will be one of the topics. PLUS: more class-like
implementations in JavaScript. I hope this book will finally put the
hipocrites of this group to shame.

Who knows? If you pray fervently enough, you might be in for a free
sample of "Secrets of the JavaScript Ninja". (Or the forthcoming "Way of
the JavaScript Samurai".)

Gregor
 
L

Lasse Reichstein Nielsen

Gregor Kofler said:
Anyway, "What does with(){...} do
and why is it so useful?" will be one of the topics.

It adds an object to the scope chain throughout its body.

This is one of the two ways to add a level to the scope chain, the other
being a function call.

Using "with" like a let-construct is dangerous, though.

function stepWatch(watch) {
for(var i = 0; i < watch; i++) {
with({i:i}) {
setTimeout(function(){alert(i + " of " + watch);}, i*1000);
}
}
}
stepWatch(5);

This appears to work fine in IE and Opera (where omitting the "with"
construct will alert "5" all the times).

Then someone runs it in Firefox, and it alerts:
0 of function watch() {
[native code]
}

The problem with the "with" construct is that you cannot control which
properties exist on the object. It differs between browsers (as
above), and it can be changed by other, misbehaved, libraries that
change Object.prototype.

So there, I'm looking forward to hearing why it's so useful :)
/L
 
J

John G Harris

It takes 3sec on my 4Mb/sec downstream DSL for the initial page
display where the download itself takes 0.39sec You may want to
consider switching from Dial-Up to something more speedy ;-)


A lot of sailors have to use dial-up via INMARSAT. Do you have a cheery
word for them ?

John
 
G

Gregor Kofler

Lasse Reichstein Nielsen meinte:
The problem with the "with" construct is that you cannot control which
properties exist on the object. It differs between browsers (as
above), and it can be changed by other, misbehaved, libraries that
change Object.prototype.

So there, I'm looking forward to hearing why it's so useful :)

Let John respond:

Gopal:
would consider the "with" statement in JavaScript to be very harmful
rather than being useful.

John:
@Gopal: There's a ton of things in JavaScript that can be "considered
harmful". Since JavaScript is such an, extremely, flexible language you
can make mistakes all over the place and not catch it. I just think that
we need to have a better understanding of how the existing features work
to give us a clearer way to move forward and to work with what we have.

I hope this makes things *a lot* clearer.

Gregor
 
J

J.S.Criptoff

The problem with the "with" construct is that you cannot control which
properties exist on the object. It differs between browsers (as
above), and it can be changed by other, misbehaved, libraries that
change Object.prototype.

Almost the same situation with named FunctionExpression:

(function () {
var watch = 0;
(function f() {
alert(watch); //-> native code...
})();
})();
 
L

Lasse Reichstein Nielsen

J.S.Criptoff said:
Almost the same situation with named FunctionExpression:

(function () {
var watch = 0;
(function f() {
alert(watch); //-> native code...
})();
})();

Wow! That's ... bad!

It seems Firefox decided to let the activation object inherit from
Object.prototype. There is nothing in the specification that requires
this, and, as you show us, it can give problems.

Neither Opera nor IE does this. Has it been bug-reported yet?
/L
 
J

J.S.Criptoff

It seems Firefox decided to let the activation object inherit from
Object.prototype. There is nothing in the specification that requires
this, and, as you show us, it can give problems.

No, Lasse, it is "special" object in scope chain created to keep
FunctionExpression name only (ES 13), no bug here.
 
A

Andrew Dupont

So what?  They all have made the wrong design decision.  Whether source code
is good is not defined by those who use it but by the source code itself.
And the source code makes its divine message known through you, its
emissary in the human realm? (And I thought I had to read the
_comments_ to understand how code worked. What a fool I was.)

You're that guy who stubbornly insists that music is not a matter of
taste — who cannot suffer the fools who dare to question the status of
Rush's _Fly By Night_ as the best album of all time in any genre.
These philistines! They ply their ears with the bleating of musical
sheep!
Yours is an "appeal to authority" fallacy, BTW.
You call foul for a logical fallacy against someone who was rebutting
your claim that two immensely popular JavaScript libraries are "junk"?
I count two right there: "appeal to ridicule" and "misplaced burden of
proof." You're the one asserting they're junk. The burden of proof is
yours.
And an ad hominem fallacy in addition.
How dare he spoil the cordial tone. Someone asks a question about
Prototype and jQuery; you reply that they're junk, and snarkily imply
he's in the wrong place. He plainly asks you why you think they're
junk; instead of mounting an argument, you make a quip. Did this guy
piss in your cornflakes?

(I'm sure you've laid out your argument in the past, and have had to
repeat it several times – so there's no reason why you shouldn't slap
it on a web server somewhere and give someone a URL.)

Now, this is Usenet; flamewars and intellectual laziness are the rule,
not the exception. But if you're pointing out the logical fallacies of
others I can only assume you aspire to a higher plane of debate.

Cheers,
Andrew
 
A

AKS

J.S.Criptoff said:
No, Lasse, it is "special" object in scope chain created to keep
FunctionExpression name only (ES 13), no bug here.

"Special" object? No, it's not:


F();

function F() {
alert(watch); //-> native code...
};
 
L

Lasse Reichstein Nielsen

J.S.Criptoff said:
No, Lasse, it is "special" object in scope chain created to keep
FunctionExpression name only (ES 13), no bug here.

Indeed, by bad. It only occurs when the inner function expression is a
named function. It's not the activation object, and it is as specified
in the standard (which probably means that the standard should be
changed, becuause that's a bad choice!)

/L
 
R

Richard Cornford

Lasse said:
Indeed, by bad. It only occurs when the inner function expression
is a named function. It's not the activation object, and it is
as specified in the standard (which probably means that the
standard should be changed, becuause that's a bad choice!)

That does seem a bit of an oversight on the part of the authors of the
specification (possibly not seeing the full consequences of what they
were writing). On the other hand the infamous JScript(tm) bug where
using an Identifier with a function expression results in the creation
of an additional function object as a named property of the current
Variable object (and during variable insanitation) already means that
using Identifiers with function expression has inconsistent
consequences. So doing so was already a bad idea.

Richard.
 
R

Richard Cornford

J.S.Criptoff said:
While c.l.j regulars are ridiculing John Resig's first
javascript book he's writing the second one - "Secrets
of the JavaScript Ninja".
<snip>

That would not necessarily have to such a bad thing as it may at first
appear to be. The first book was published in 2006 and it is possible to
learn a great deal in two years. Granted I don't think that John Resig's
attitude will lend itself to facilitating his learning anything
effectively.

Richard.
 
R

Richard Cornford

Andrew said:
And the source code makes its divine message known through you,
its emissary in the human realm? (And I thought I had to read
the _comments_ to understand how code worked. What a fool I
was.)

It is very often a characteristic of 'good' source code (at least in
higher level languages) that the code can easily be understood by
reading the source code.

However, the last significant discussion of the Prototype.js source code
that we had here (the link, via Google groups, to that discussion is in
one of the posts in this thread) showed that the authors of Protoype.js
obviously did not understand the code they were writing (instead finding
themselves victims of code that exhibited behaviour that conformed with
their expectations by no more than coincidence (but then only on the
browsers were they had observed that behaviour)). Under those
circumstances the code itself if more informative than the comments
because an author who does not understand the code they are writing
cannot comment it in an informative way.
You're that guy who stubbornly insists that music is not a
matter of taste - who cannot suffer the fools who dare to
question the status of Rush's _Fly By Night_ as the best
album of all time in any genre. These philistines! They ply
their ears with the bleating of musical sheep!

I didn't think that was an appeal to authority, more of an appeal to
bulk, in some sens.
You call foul for a logical fallacy against someone who was
rebutting your claim that two immensely popular JavaScript
libraries are "junk"?

That wasn't a rebuttal, more of an excuse for using the code regardless
of any informed assessment of its quality.
I count two right there: "appeal to ridicule" and "misplaced
burden of proof." You're the one asserting they're junk. The
burden of proof is yours.
<snip>

Where the 'proof' is already a matter of public record, and familiar to
anyone who has any more than superficial record of participating in this
group, there is no longer any burden of proof at all.

Still, if you want examples they are just a short download away.
Downloding the latest version of Prototype.js (1.6.0.2) I wondered how
long it would take me to find an example of something being done
sufficiently badly for that to be easily and unambiguously demonstrated.
The answer was under three seconds. During the first scroll through the
code, not even looking at most of the details, I noticed this:-

| if (Prototype.Browser.WebKit || Prototype.Browser.IE)
| Object.extend(String.prototype, {
| escapeHTML: function() {
| return this.replace(/&/g,'&amp;')
| .replace(/</g,'&lt;')
| .replace(/>/g,'&gt;');
| },
| unescapeHTML: function() {
| return this.replace(/&amp;/g,'&')
| .replace(/&lt;/g,'<')
| .replace(/&gt;/g,'>');
| }
| });

- which is adding a couple of escaping/unescaping methods to the -
String.prototype - object based upon a condition. Seeing it I asked
myself whether the author had made the rookie mistake that every web
development novice always makes (and the thing I deliberately double
check every time I ask someone to write an escaping/unescaping function
for any purpose), and the answer was a very obvious "yes they have".

One of the arguments paraded in favour of these libraries is that they
are examined, worked on and used by very large numbers of people, and so
they should be of reasonably high quality because with many eyes looking
at the code obvious mistakes should not go unnoticed. My experience of
looking at code from the various 'popular' libraries suggests that this
is a fallacy, because (with the exception of YUI (for obvious reasons))
all of the 'popular' library contain numerous obviously stupid mistakes.
The problem probably being that it does not matter how many people may
look at, review or use, any particular piece of code, if none of them
understand what they are doing none of them are capable of spotting the
obvious mistakes.

In this case we have a very obviously stupid use of user agent string
based browser detection to make a decision that would be more logically
made with feature detection. That is, the attempt is to add two methods
to the - String.prototype - in environments were those methods do not
already exist. Obvioulsy the is a one-to-one relationship between -
String.prototype.escapeHTML - having trueness and an environment where
a - String.prototype.escapeHTML - has been implemented. While the
relationship between a user agent sting an a -
String.prototype.escapeHTML - method is at best tenuous, and certainly
not guaranteed to be comprehensive or continuous over time.

But that is not the rookie mistake I alluded to above. That mistake is
that the escaping and unescaping methods are not symmetrical. That is,
if you apply the second to the output of the first you will not always
end up with the character sequence you start with. I.E.:-

<script type="text/javascript">
alert('&lt;'.escapeHTML().unescapeHTML()); //alerts "<"
alert('&amp;lt;'.unescapeHTML().escapeHTML()) //alerts "&lt;"
<script>

- and that is pretty bad by anyone's standards (except maybe VK's).

Richard.
 
J

J.S.Criptoff

<snip>

That would not necessarily have to such a bad thing as it may at first
appear to be. The first book was published in 2006 and it is possible to
learn a great deal in two years. Granted I don't think that John Resig's
attitude will lend itself to facilitating his learning anything
effectively.

Richard.

In two years? Are you kidding, Richard? John Resig gave a presentation
for the local ACM of Northeastern University and covered the basics of
javascript a few weeks ago. Weeks. Look at his slide, Richard:

Type coersion
0 == false
null == false
!"foo" == false

And listen to guru-ninja's explanation: "Zero is equal to false. Zero
gets coerced into becoming Á boolean value... Same thing with
nulls...".

from 5:50
http://video.google.com/videoplay?docid=-7485992465859932389
 
T

Thomas 'PointedEars' Lahn

Richard said:
I didn't think that was an appeal to authority, more of an appeal to
bulk, in some sens.

Quoting people who approve of something and concluding that therefore this
something must be good is the classical example for the logical fallacy of
appeal to authority, also known as "ipse dixit" ("he himself said it").

Unfortunately, out of general appreciation of the other person, several
regulars around here tend to fall victim to this fallacy as well, without
recognizing it. We should strive to avoid such fallacious arguments,
especially as they only weaken a good case when confronted with an argument
that is fallacious as well.

http://en.wikipedia.org/wiki/Appeal_to_authority


PointedEars
 
R

Richard Cornford

That really should have been; "... have to be such a bad thing ..".
In two years? Are you kidding, Richard?

Not at all. The bulk of what I have learnt about javascript was learnt
in the period from 2002 to 2004. Two years is plenty of time, if you put
the effort in and are receptive to the idea that you really didn't know
it all to start with.
John Resig gave a presentation for the local ACM of
Northeastern University and covered the basics of
javascript a few weeks ago. Weeks. Look at his slide,
Richard:

Type coersion
0 == false
null == false
!"foo" == false

And listen to guru-ninja's explanation: "Zero is equal to
false. Zero gets coerced into becoming ? boolean value...
Same thing with nulls...".
<snip>

Well, I did say that his attitude would get in the of his potential to
learn. He dropped into a thread on this group with the subject
"prototype - Good/Bad/Why?", which commenced 15th February 2008 and in
which the section of his first book that reads:-

"In JavaScript, null, 0, '', false, and undefined are all equal (==)
to each other, since they all evaluate to false. This means that if
you use the code test == false, it will evaluate true if test is
also undefined or equal to null, which may not be what you want."

- and goes on to state that:-

"Listing 3-12. Examples of How != and == Differ from !== and ===
// Both of these are true
null == false
0 == undefined" - John Resig: Pro JavaScript Techniques. 2006

- was directly criticised for its demonstrably false statements about
javascript (and also the competence of the book's technical editor (who
apparently works for Google) as a result of letting those errors pass
uncorrected). If he had hung around and paid attention to his critics he
would not have been repeating that same mistake just a couple of weeks
ago. But then the code:-

| makeArray: function( array ) {
| var ret = [];
|
| // Need to use typeof to fight Safari childNodes crashes
| if ( typeof array != "array" )
| for ( var i = 0, length = array.length; i < length; i++ )
| ret.push( array[ i ] );
| else
| ret = array.slice( 0 );
|
| return ret;
| },

- was still in the last (1.2.3) release of JQuery more than six months
after John Resig had been directly asked to justify it during his
previous visit to this group. He did not attempt to justify it (which
would not have been that difficult if it could be justified at all [1]),
but apparently also did not grasp the reason for the criticism.

Interestingly I observed Matt Kruse (who is the nearest thing to a
supporter JQuery has among the regular contributors to this group, and
someone who can easily outgun anyone directly involved in JQuery
development when it comes to javascript) directly asked however was
responsible for the - if ( typeof array != "array" ) - code to own up to
it in a post on the JQuery development group. However, when I checked
back a week later to see if anyone had the intellectual integrity to own
up to their mistake I found that Matt's post had been deleted from the
group.

Well, we get used to the intellectual freedom of Usenet, where criticism
is just a matter of public record. While those more familiar with
blogging and (self?) moderated Google forums might see deleting their
critics as a satisfactory approach to avoiding realising their mistakes.

Richard.

[1] For those who need to be told; javascript primitives and native and
built in objects may only result in the strings 'string', 'undefined',
'object', 'function', 'number' and 'boolean' from a typeof operation
(with no known implementation bugs in this area). Host objects are
allowed to return any value (or even throw exceptions), such as when the
methods of ActiveX object result in the string 'unknown' when a typeof
operation is applied to them. So, if the code - if ( typeof array !=
"array" ) - makes any sense at all there must be an object property of a
host object in a browser (and since JQuery only works with the default
configurations of just four browser it must be one of those four
browsers) with a - slice - method that results in 'array' when a typeof
operation is applied to it. It should not be at all difficult to name
the object/property and browser/browser version in question, and so
justify code that otherwise looks like a long running mistake that is
being repeated in the face of direct criticism.
 
R

Richard Cornford

Thomas said:
Quoting people who approve of something and concluding that
therefore this something must be good is the classical example
for the logical fallacy of appeal to authority, also known as
"ipse dixit" ("he himself said it").

It is certainly an appeal to something, but it often feels as if that
something is not "authority" much of the time. After all, why should
NASA, Apple or CNN be considered authorities on web development at all.
You would not cite someone who was perceived as having web development
expertise in support of opinions on space exploration, computer hardware
design or news broadcasting so why attempt to do so the other way
around.

And Google is just a joke in any list of 'authorities' on web
development. I noticed at the beginning of last week that they have
(after just half a decade) finally managed to improve the accuracy of
their adding-up code on Google groups to an accuracy better than the
previous plus or minus 60% (and so radically re-arrange their 'all time
top posters' list for comp.lang.javascript), and the next day I tried to
show someone that they had done something about that code only to find
that the page containing the list was no longer working at all (and
stayed non-functional for the rest of the week). Their code is clearly
such a mess that whenever they try to fix one of its faults it promptly
unravels somewhere else.
Unfortunately, out of general appreciation of the other
person, several regulars around here tend to fall victim
to this fallacy as well, without recognizing it.

Yes, and it seems to be getting to be me who keeps being cited as an
authority. I suppose that I probably should not worry about that from a
personal point of view because for each opinion of mine that is
accurately represented there will also be reasoned statement of
justification for that position somewhere on the public record. Though
it is perhaps a pity that reasoned arguments are apparently not seen as
standing or falling independently of any 'authority' that makes them,
and so should be presented in themselves.
We should strive to avoid such fallacious arguments,
especially as they only weaken a good case when confronted
with an argument that is fallacious as well.

That would be good. But I can certainly see how the Prototype.js/JQuery
argument is starting to get so old that people are reverting to
knee-jerk generalisation as an alternative to going over it all again.

Richard.
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top