How do I POST a form to a new window?
Change example to use method="post"
-Saarikumpu
How do I disable the right mouse button?
Fix the grammar
- Stockton
How can I see in javascript if a web browser accepts cookies?
Replace links to cookiecentral and galasoft with MDC link
- Lahn
If I missed something, say something.
Thanks.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
| return (this + "").replace(/^\s+|\s+$/g, '');
Should be:
("" + this)
See in JScript:
var o = {toString : null, valueOf : null};
window.alert('' + o); //empty string
window.alert(o + ''); //[object]
var xhr = new ActiveXObject('Microsoft.XMLHTTP');
window.alert('' + xhr); //empty string
window.alert(xhr + ''); //undefined
In your thread about "Code Guidelines" i payed attention about that:
<URL: http://groups.google.bg/group/comp.lang.javascript/msg/1528f612e31f09fe>
Happy New Year!
The Contributors section in the Notes is years out of date.
[...]
>> If I missed something, say something.
>>
>> Thanks.
>
> The Contributors section in the Notes is years out of date.
Certainly is. Anyone want to propose a draft?
Right, I see that now. Weird! It seems that with Host object in IE, the
+ operator behaves differently.
I've changed the example to:-
| if(!String.prototype.trim) {
| String.prototype.trim = function() {
| // XXX IE ("" + this) and not (this + "") for Host obj
|
//http://groups.google.com/group/comp.lang.javascript/msg/fe387847c719119a
| return ("" + this).replace(/^\s+|\s+$/g, '');
| };
| }
Look OK?
^^ ^^
Would be better to use either double or single quotes, consistently :)
[...]
--
kangax
I propose you add my name. :)
> Right, I see that now. Weird! It seems that with Host object in IE, the
> + operator behaves differently.
Yes, but addition operator have different behavior not only with host
objects. See below with native object:
var o = {toString : null, valueOf : null};
try {
window.alert(String(o));
}catch(e) {
window.alert(e instanceof TypeError); //[[DefaultValue]] throw
TypeError
}
window.alert('' + o); //empty primitive string value
window.alert(o + ''); //[object]
They have much more complex algorithm, from presented in ECMA262-3
documentation. And they, definitely doesn't follow specification in
that point.
> Asen Bozhilov wrote:
>> var xhr = new ActiveXObject('Microsoft.XMLHTTP');
>> window.alert('' + xhr); //empty string
>> window.alert(xhr + ''); //undefined
>>
>> In your thread about "Code Guidelines" i payed attention about that:
>> <URL:
>> http://groups.google.bg/group/comp.lang.javascript/msg/1528f612e31f09fe>
>>
>
> Right, I see that now. Weird! It seems that with Host object in IE, the
> + operator behaves differently.
Yet another bug triggered by unwise programming.
> I've changed the example to:-
> | if(!String.prototype.trim) {
Should have a space after `if'; it is not a function call.
> | String.prototype.trim = function() {
See, if you used a method to do this instead you would not be in such a
need of writing identifiers twice. That is one advantage.
> | // XXX IE ("" + this) and not (this + "") for Host obj
^^^^
Should be lowercase (that error goes like a red thread through all your
postings; perhaps you have not understood the concept behind it at all?),
and "object" should not be abbreviated like this.
Should be a multi-line documentation comment using a proper task tag:
/* NOTE: JScript requires ("" + this) for host objects */
(But this would be superfluous without implicit typecasting anyway.)
> |
>
//http://groups.google.com/group/comp.lang.javascript/msg/fe387847c719119a
> | return ("" + this).replace(/^\s+|\s+$/g, '');
> | };
> | }
>
> Look OK?
No. There is also no need of or advantage in relying on implicit
typecasting.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
> Yet another bug triggered by unwise programming.
No. That is yet another bug from Microsoft ECMA-262 implementation,
called with name JScript. In normal case:
new ActiveXObject('Microsoft.XMLHTTP') + ''; //expected TypeError
And nobody suggest to do it that.
> No. There is also no need of or advantage in relying on implicit
> typecasting.
| ECMA 5 15.5.4.20
| NOTE The trim function is intentionally generic;
| it does not require that its this value be a
| String object.
| Therefore, it can be transferred
| to other kinds of objects for use as a method.
ActiveXObject has neither toString nor value of and so String
concatenation throws there.
window.external.toString; // undefined
Comment changed to:-
// XXX JScript ("" + this), not (this + "") for objects w/o toString.
//http://groups.google.com/group/comp.lang.javascript/msg/fe387847c719119a
> Asen Bozhilov wrote:
>> Garrett Smith wrote:
>>> Right, I see that now. Weird! It seems that with Host object in IE, the
>>> + operator behaves differently.
>>
>> Yes, but addition operator have different behavior not only with host
>> objects. See below with native object:
>>
>> var o = {toString : null, valueOf : null};
> That would be expected to throw an error, although it does explain
> the problem with Host object.
It does not; check your assumptions. And there is that ominous "Host
object" again -- when will you get it?
> THe problem is that the error occurs in
> calling toString and valueOf throws.
Parse error.
> ActiveXObject has neither toString nor value of and so String
Has what?
> concatenation throws there.
Throws what? And no, that is _not_ necessarily the reason why.
> window.external.toString; // undefined
>
> Comment changed to:-
> // XXX JScript ("" + this), not (this + "") for objects w/o toString.
>
//http://groups.google.com/group/comp.lang.javascript/msg/fe387847c719119a
Neither writing nor reading appear to be the forté of the current FAQ
maintainer -- goodnight, cljs.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300...@news.demon.co.uk>
> Neither writing nor reading appear to be the forté of the current FAQ
> maintainer -- goodnight, cljs.
So what? I told you before. If you have any problem in real life, go
outside and take a fresh air, before start blaming everyone in
c.l.js.
I shall be reasonably content with anything that does not include my
name.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (RFCs 5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFCs 5536/7)
No. It is customary to convert to String with +"" and not ""+ - which
means that code correctly following the FAQ and working in 'all'
browsers may later get 'tidied' into the usual form and then work in
'all' browsers but one. If it works properly in at least as many
browsers, I suggest
return String(this).replace(/^\s+|\s+$/g, "");
which is only one character longer.
==== On the Web,
function countdown(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getUTCMonth()
var todayd=today.getUTCDate()
...
still has not been corrected. But there are obvious sibling instances
of function countdown() which lack the prime fault, so it probably was
not in the original. Another part of the file has a brace of 1800-year
errors.
--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
It looks completely odd to me. If you test for String.prototype.trim,
then there's no sense in coercing the argument to string, as in (this
+ '') or ('' + this), because the trim method should only be used with
strings. The trim() method proposed in the FAQ looks like a mutant,
and I doubt that the FF native code does such a coercion.
I think that the developer should test whether the argument is a
string before trying to use this method, I mean that kind of check
should be done outside the trim method.
By the way, there's an interesting article about this subject at:
http://blog.stevenlevithan.com/archives/faster-trim-javascript
A very fast regex was proposed there (trim1)
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
The reasons are explained in the article.
Cheers,
JR
[...]
>> Look OK?
>
> It looks completely odd to me. If you test for String.prototype.trim,
> then there's no sense in coercing the argument to string, as in (this
> + '') or ('' + this), because the trim method should only be used with
> strings. The trim() method proposed in the FAQ looks like a mutant,
> and I doubt that the FF native code does such a coercion.
>
You should check those doubts against the specification.
Asen was correct in bringing this up and in the workaround for the
JScript bug he mentioned.