FAQ Suggestion

D

dhtml

Tried mailing the FAQ maintainer but the mail bounced.

The FAQ entry of topic:
http://www.jibbering.com/faq/#FAQ4_15

DocDom = (document.getElementById?true:false);
DocAll = (document.all?true:false);
DocStr=''
if (DocAll) DocStr="return document.all[id]"
if (DocDom) DocStr="return document.getElementById(id)"
GetRef=new Function("id", DocStr)
if (DocStr=='') { DynWrite=new Function("return false") } else {
DynWrite=new Function("id", "S", "GetRef(id).innerHTML=S; return
true")
}

Is a very poor quality example. Anyone reading that code who knows
what they are doing would probably consider the advice in the document
worthless.

It should be revised to not use the function constructor, for one. It
should definitely not declare variables without the var keyword. The
DocDom variable is also questionable. Does "DocDom" being true imply
something other than "document.getElementById" exists?

The explanation before the example is sufficient.

It would be a good idea to add something about script tag insertion.
This comes up fairly often.

========================================
SCRIPT tags inserted with innerHTML will not be evaluated in most
circumstances. Appending a
script tag will cause the script to be executed in most browsers.
 
R

RobG

Tried mailing the FAQ maintainer but the mail bounced.

The best method has been to follow the advice in FAQ 5:

<URL: http://www.jibbering.com/faq/#FAQ5 >


Constructive criticism is welcome but insufficient to get entries
changed. The most successful process has been to post the suggested
revised entry here with reasons for the update.

The FAQ maintainer should then update the FAQ (or not) depending on
the response the post. If the current maintainer continues to be
elusive, perhaps it's time to look for a new volunteer.
 
J

Jim Ley

Tried mailing the FAQ maintainer but the mail bounced.

the (e-mail address removed) one? what message? (e-mail address removed) also
works and has a different set of filtering/spam protection on it.

I do agree on the updates - do we have a new maintainer that I should
give access too?

Cheers,

Jim.
 
D

Dr J R Stockton

In comp.lang.javascript message <8c1dcb4b-f395-4ff4-aa26-5913024bdd3a@y1
9g2000prn.googlegroups.com>, Thu, 7 Aug 2008 17:41:13, dhtml
Tried mailing the FAQ maintainer but the mail bounced.

That shows why FAQ 5.2 needs a change.
The FAQ entry of topic:
http://www.jibbering.com/faq/#FAQ4_15

DocDom = (document.getElementById?true:false);
DocAll = (document.all?true:false);
DocStr=''
if (DocAll) DocStr="return document.all[id]"
if (DocDom) DocStr="return document.getElementById(id)"
GetRef=new Function("id", DocStr)
if (DocStr=='') { DynWrite=new Function("return false") } else {
DynWrite=new Function("id", "S", "GetRef(id).innerHTML=S; return
true")
}

Is a very poor quality example. Anyone reading that code who knows
what they are doing would probably consider the advice in the document
worthless.

Clearly postfix ?true:false should be replaced by prefix !! .
It should be revised to not use the function constructor, for one. It
should definitely not declare variables without the var keyword.

If the whole is encased in a function (as I (an original *user*) did),
the lack of var makes then usefully global.
The
DocDom variable is also questionable. Does "DocDom" being true imply
something other than "document.getElementById" exists?

The explanation before the example is sufficient.

One wonders whether "insufficient" was intended.


The common way now is AIUI to use either DOM methods or less modern
document.getElementById(ID).innerHTML = S

In either case, the code should, for overall brevity and structure, be
encapsulated in, say,
function Wryt(ID, S) { /* ... */ }
and it would be good to see that in the FAQ.

If it is necessary to support browsers without document.getElementById,
one can include something like
if (document.all && !document.getElementById) {
document.getElementById =
function(id) { return document.all[id] } } ,
the documentation of which needs a note indicating that and how it is
not fully equivalent.
 
D

dhtml

the (e-mail address removed)  one?  what message?  (e-mail address removed) also
works and has a different set of filtering/spam protection  on it.

I used the gmail one the second time. The mail I sent to Randy Webb
([email protected]) bounced.

The one I sent to your gmail account did not.
I do agree on the updates - do we have a new maintainer that I should
give access too?

I don't think we do. Do we?
 
D

dhtml

In comp.lang.javascript message <8c1dcb4b-f395-4ff4-aa26-5913024bdd3a@y1
9g2000prn.googlegroups.com>, Thu, 7 Aug 2008 17:41:13, dhtml


That shows why FAQ 5.2 needs a change.

Sure.

Clearly postfix  ?true:false  should be replaced by prefix !! .

I don't think the DocDom variable needs to be declared at all. I don't
think this needs to be function, either. el.innerHTML = s is
sufficient.

Declaring global variables inside a function by omitting var makes the
globals hard to notice. It looks like a mistake from the careful eye,
and would go unnoticed by a quick lookover. It can also cause an error
if there is an element with the same name

The common problem is the variable i used in loops;

Douglas Crockford actually advises not using var:
http://yuiblog.com/blog/2008/04/16/global-domination-part-two/

But provides no explanation other than: "There's a bug in IE."
var pity = this.pity || {};alert(pity)

No explanation of what happens in IE or what should happen.

The problem with omitting var in IE is that it can create conflict
with objects that get added to the global object as apparently
readonly.

<div id=Menu></div>
<script>
Menu = {};
</script>

Error in MSIE.

However:
<div id=Menu></div>
<script>
var Menu = {};
</script>

Will not cause an error.

IE8 could fix this for standards mode, and only fall back to the buggy
behavior for quirks mode, but they probably won't. They could not
reproduce the bug I filed on this.
One wonders whether "insufficient" was intended.

No, I meant 'sufficient' there's just a simple explanation of
something like:
el.innerHTML = "hello <em>world</em>"; or something like that. It
seemed sufficient. There's no need to write a helper function for
innerHTML. It woul only make the code slower and more complex.
 
M

Mike Duffy

Declaring global variables inside a function by omitting var

Good Lord! This explains a lot of my problems. I always thought that they
were global only if declared explicitely as a var *outside* of all
functions.

Thanks for the tip! I thinks it's time for a little code review. In any
case I usually declare everything in functions, mostly out of habit from
using more restrictive languages, so it should not turn up a lot of
changes.

One little question though. When does the global definition dissapear? The
reason I ask is because am restricted to using static pages, and where cgi
or asp should really be used I instead have a habit of building a new page
into a string and then using document.write if I need to change the <head>
section or simply changing the innerHtml on an element which comprises the
entire <body> section. I have had "issues" in the past regarding globals in
the resulting javascript.

Do variables declared within event handlers (i.e. <img onLoad="blah blah"
get treated the same way? (i.e. do they become global?)
 
T

Thomas 'PointedEars' Lahn

Mike said:
Good Lord! This explains a lot of my problems. I always thought that they
were global only if declared explicitely as a var *outside* of all
functions.

In a way, you are correct, and "dhtml" is not (which has been explained
before here). Because what has not been declared a variable will never
magically become one. Instead, use of an undeclared identifier left-hand
side in an assignment leads to its resolution along the scope chain; if no
object in the scope chain has a property with that name, the Global Object
will be augmented with one. The most important difference to a global
variable is that this new property can be deleted.


PointedEars
 
M

Mike Duffy

That's not a good way to write maintainable code.

You're telling me! One of the hardest things is working with strings,
because you are building the html into strings which contains the javacript
within quotes, which itself needs to have quoted material. It gets
especially tricky when you want to define on-the-fly html tags with in-line
event handlers.

Of course, if I had a business-related site I would pay extra and use ASP /
AJAX / CGI.

If anyone is interested, you need to do a "document.close", then
"document.open" before the "document.write" if you want a web page with a
new <head> section. You can see an example of a dynamically-generated page
on a static server if you go to my javascript phone poem generator. Go to
my poetry page at:

http://pages.videotron.com/duffym/poetry.htm

and take the exam at the bottom of the page.
 
T

Thomas 'PointedEars' Lahn

dhtml said:
Thomas is technically correct.

It follows from:
11.13.1 Simple Assignment (= )
and
8.7.2 PutValue(V, W)

Where PutValue step 6, a property is assigned to the global object.

JFTR: The chain of reasoning is a little bit more complex than that. Step 1
of the algorithm of section 11.13.1 eventually leads to section 10.1.4
("Scope Chain and Identifier Resolution"), which defines that the base
object of the Reference value returned would be `null', which then has
meaning in the algorithm of PutValue().
However, MSIE has different behavior, depending on the identifier.

Does it?
1.
<div id='Menu'></div>
<script>
this.Menu = {} ;
</script>

No Error

2.
<div id='Menu'></div>
<script>
Menu = {} ;
</script>

Error in IE8 in standards mode.

IE 8 is still *beta*, I would not care about this UA until it is at least a
Release Candidate. However, this behavior is not exactly new to that
version. In fact, it is an important reason for the general recommendation
to declare variables.

My hypothesis stands that in the MSHTML runtime environment there is a host
object in the scope chain before the Global Object that has names and IDs of
elements as read-only properties to refer to the element objects that
represent the elements in the DOM (whether they have the ReadOnly attribute
or not is unknown, at least they cannot be written to, which would be
reasonable considering their initial value). Your observation that writing
directly to the property of the Global Object does not cause an error would
only support this hypothesis.
https://connect.microsoft.com/IE/feedback/ViewFeedback.aspx?FeedbackID=354814
Status Closed (Not Reproducible)

Assigning a property to the global object works without error in IE
(example 1) but in contrast example 2 causes an error.

Because those two statements are not equivalent. The first one does not use
the scope chain; the second one does.
Why does Douglas Crockford advise not using var for globals? What's the
IE bug he mentions in passing?

http://yuiblog.com/blog/2008/04/16/global-domination-part-two/

| JavaScript provides three ways of declaring a global variable,

Which is incorrect, as I have explained. (It is even more wrong because
"JavaScript" is the incorrect term here. We are dealing with several
ECMAScript implementations in HTML UA runtime environments; one of them,
Microsoft JScript, or the environment it runs in, MSHTML, has either a
peculiarity sanctioned by the Specification, or a bug.)
| and they all have problems.
...

| IE gets the second form wrong, so that responsibly
| adaptive programs fail when using constructs like
|
| var pity = this.pity || {};

What's this bug in IE?

I do not know. It is to be expected that `pity' is assigned either the
true-value of `this.pity' or the Object object reference, and that is what
happens in all IE versions from 4.01 to 8.0 beta 1. Tested with these
bookmarklets (in order, after refresh):

// alerts "[Object object]"
javascript:var pity = this.pity || {}; window.alert(pity);

// alerts "42"
javascript:this.pity = 42; var pity = this.pity || {}; window.alert(pity);
All globals should be declared explicitly (using var). It's explicit and
it avoids the bug I mentioned (above).

It remains to be seen whether it is a bug.
Global functions can be declared with a FunctionDeclaration.

That would be

function foo(/* ... */)
{
// ...
}

They can also be declared with a FunctionExpression as the right-hand side
of a VariableDeclaration's initialization:

var foo = function bar(/* ... */) {
// ...
};

or

var foo = function(/* ... */) {
// ...
};

But I would resort to that only when a condition is placed on the assignment.

Incidentally, ISTM there is no way to conditionally declare a variable other
than this:

if (condition)
{
eval("var foo;");
}

What do you think?


PointedEars
 
T

Thomas 'PointedEars' Lahn

Jim said:
I do agree on the updates - do we have a new maintainer that I should
give access too?

We might have one.

As I have said in [1] before, I have been considering to contribute in that
way, too, for quite a while. That started when the current maintainer
refused to think about any changes based upon their own initiative and even
argued against posting conventions recommended in the FAQ[2], which is not
what I think a responsible FAQ maintainer should do.[3]

At that time, I actually considered supporting him in the task rather than
taking over, but I had much too little free time on my hands even for that.

This has changed now that I am dealing with fewer but larger projects in my
job, and particularly at this time of year where most customers are on
holiday.

Therefore, I am hereby volunteering for the job.

As I have said repeatedly, I second that the FAQ desperately needs
improvement in several places (e.g. [4]), and I am going to do my
best to make it so.

[1] <[2] <[3] <[4] <<
Some things about me:

- IIRC, I have been dealing with JavaScript, JScript, and other ECMAScript
implementations for about 12 years now, of those about 9 professionally.
I have been doing Web development for about 14 years now (while my home
page certainly does not show it [yet], but I hope my solutions elsewhere
and my record here do). That includes Apache and IIS Web server
administration. (I am only mentioning this because I consider it
important for the maintainer of a technical FAQ to know their stuff well.)

- I have written several multi-purpose script libraries and published them
under the GNU General Public License. (Follow "Scripting" on my home page
or ask Google).

- I have been maintaining the ECMAScript Support Matrix for 3 years, which
is hopefully going to be a comprehensive comparison of the features of
existing ECMAScript implementations one day.

- I have never written any "Javascript" book ;-)

- I have been regularly contributing to technical Usenet newsgroups,
particularly de.comp.lang.javascript and this newsgroup, for about 6
years now (with a one-year pause in-between). I have made some minor
contributions to the de.comp.lang.javascript FAQ, but I have never
maintained a FAQ before.

- I consider myself a hacker[1], which is the main reason why I think we
need a good FAQ: (free) time is too precious to be wasted on solving old
problems; existing solutions should be able to be found quickly and
referred to more easily. They should be understandable by anyone willing
to learn without much asking further questions about them here.

[1] <http://www.catb.org/~esr/faqs/hacker-howto.html>

- I am born German, living and working in Switzerland since about 2
years. While my English has been rated quite good recently, when
implementing changes I might still rely on the better judgment of those
who speak it as native language.

- I have a full-time job and I am continuing my university-level studies in
computer science with distance learning, which means that I would do this
in what is left of my free time. I am going to reserve a time slot for
regular FAQ reviews on the weekends. I might be able to do little changes
in-between.

- I would maintain the FAQ under one condition: You would have to trust me
in the regard that after I have carefully considered all arguments
provided here, I would make the final decision what is or is not going to
be in the FAQ at a certain point (unless Jim objected to that; it is his
Web site, after all).

If you can accept that, just drop me a note, and I will be glad to take over
and to set things in motion again.


Regards,

PointedEars
 
L

Laurent vilday

Thomas 'PointedEars' Lahn a écrit :
We might have one.

Well, not you I hope for the sanity of FAQ readibiliy.
At that time, I actually considered supporting him in the task rather than
taking over, but I had much too little free time on my hands even for that.

If only it was true, at least clj would get rid of you, but it is not
true, not at all. You have *way* *too* much free time on your hands,
just take a look at the posting time of your boring posts here at clj
(not even looking at the de.* hierarchy which I suppose is full of your
silly posts : "This is not javascript, it is JavaScript." Pfff,
ridiculous little one)
- I would maintain the FAQ under one condition: You would have to trust me
in the regard that after I have carefully considered all arguments
provided here, I would make the final decision what is or is not going to
be in the FAQ at a certain point (unless Jim objected to that; it is his
Web site, after all).

Good lord, that is the *main* reason to *NOT* choose you, and there are
a lot more reasons to not to. For a start, You can't be trusted.
Trustable people doesn't consider themselves as superior from the
others. Which is obviously not the case with you.
 
D

dhtml

Thomas 'PointedEars' Lahn a écrit :
Good lord, that is the *main* reason to *NOT* choose you, and there are
a lot more reasons to not to. For a start, You can't be trusted.
Trustable people doesn't consider themselves as superior from the
others. Which is obviously not the case with you.

It's not much of a position of authority, though it could potentially
be used to scare off/insult new users. I think if that were to happen,
it would be good reason to change the FAQ maintainer immediately. The
FAQ maintainer should be a model citizen on the group, not pointlessly
argumentative.

Whoever takes over ought to take the comments there under
consideration.
http://groups.google.com/group/comp.lang.javascript/msg/42ff92cf482c94e0

I'm half tempted to volunteer, but I'm starting another project right
now. Its related to something Microsoft says is "designed to work in
standard mode out of this box." Something that "will take the web
experience beyond the page whether you are a web developer writing to
standards or a user.."

How about Lasse? or Bart Van der Donck? Whoever it is, should have
good knowledge of Ecma-262 r3 and Browsers and, as I said before, a
model citizen for the newsgroup (sans insults, arguing over minutiae
to miss the point, et c).

Garrett
 
D

Dr J R Stockton

In comp.lang.javascript message <2413112d-ea25-48f6-9895-2f9aa10f7b61@w3
9g2000prb.googlegroups.com>, Sun, 10 Aug 2008 10:45:21, dhtml
Whoever takes over ought to take the comments there under
consideration.
http://groups.google.com/group/comp.lang.javascript/msg/42ff92cf482c94e0


I see two approaches for a new maintainer :
Rework it completely from his own knowledge, and present that as a
draft for comment;
Take it as it is, and ask for new comment.

Since, for a year and a half, most then all of comment has been ignored,
it would take a weirdo masochist to work through the lot via Google or
FAQ**TRY; but it would be sufficient to be guided by what is now thought
important.


The FAQ Notes are anonymous and undated; and it is not clear whether
they are maintained. The only indication of authorship that I recall is
their being on the jibbering site, which falsely suggests Jim Ley
(though they are clearly not in his style of writing; and I do know who
wrote them).

IMHO, either the FAQ Notes should be taken over, fully, by the FAQ
maintainer (probably an unreasonable suggestion!); or the FAQ should be
re-worded to make it perfectly clear that the Notes are not maintained
by the FAQ system and so, as far as the group is concerned, have no more
authority as an expression of current collective thinking than the pages
of, for example, myself or Microsoft.

In any case, the Note pages should be given the name of who/what is
responsible and an appropriate date - as is the case for all worthwhile
documents.


The FAQ earlier was, and again is, very weak on Date and Time matters;
IMHO, the intermediate state should be restored or something better
provided. It is also weak on RegExp; the substring "regex" occurs only
once, in a link in Sec 4.16, and "Regular" in that sense also occurs
only in 4.16. It has nothing on sorting.

FAQ 4.30, lastModified : the facts need checking by someone with access
to or reliable memory of a large number of browsers of various ages. It
contains "though problems can occur if the browser returns only two
digits for the year" which *might* now be better replaced by "though
errors may occur with older browsers which return only two-digit years
or omit offset indication".

ECMA4 ought to add document.lastUploaded, being _EITHER_ a String or
Number representing the number of [milli]seconds from 1970.0 UTC or
other fixed epoch _OR_ a copy of the Last-Modified header; that would
make things much simpler. I think new Date(Last-Modified) will always
be correct. If there is no such header, the property should (choose and
define) either not exist or be respectively NaN or "".
 

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,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top