0. You should have posted using your real name to avoid your posting being
misinterpreted as spam.
0.1. You should not have posted using Google Groups, from which most spam
messages to Usenet are injected nowadays.
0.2. You should have made yourself aware of the other shortcomings of
Google Groups with regard to Network News, such as lack of proper
automatic line-break. Your posting consists of a single line of 335
characters, which is inacceptable for plain-text Network News,
including Usenet (where you have posted to).
Postings should be properly formatted and lines should not exceed 80
characters per line. One recommendation is to format the line so that
it ends before the 76th character, to that there is room for quotation
characters (`> > '). See also <
http://jibbering.com/faq/#posting> pp.
1. There is no "Javascript" (or "javascript"). You and your readers need to
become aware that they are writing code that is executable in and
(because of different host environments, necessarily) executed by
several different implementations of ECMAScript that differ from one
another:
<
http://PointedEars.de/es-matrix>
2. Improve your code style so that your readers learn how to write easily
readable (and thus inexpensively maintainable) code. The comma should be
followed by at least one space character.
3. Verbatim string literals may not be continued on the following line
(some ECMAScript implementations, especially those conforming to Edition
5, support continuing a string literal on the following line which has
been delimited with a `\' character on the preceding line. See section
7.8.4.).
This code of yours does not _compile_:
var text = "You will replace him with new word, so go ahead and type
any word into the input box now!";
Modify your examples so that they compile and run as they are when copy
pasted. This can be accomplished best here with using string
concatenation, slicing the one string value into two so that the line
length does not exceed a reasonable common limit (such as 67 characters,
which is the prevailing standard for fixed-width printouts):
var text = "You will replace him with new word, so go ahead"
+ " and type any word into the input box now!";
4. Use window.alert(…) instead of alert(…), to make explicit that you intend
to call a method of the object referred to by the `window' property
of the global object, which does _not_ belong to any programming language
(anymore; but to the AOM/DOM API instead). The same applies to
window.prompt(…).
5. Your definition of "word" is incorrect or your description of the replace
example is imprecise.
text.replace(/him/gi,repText)
will _return_ the value of `text' with all _case-insensitive_
_occurences_ (substrings) of "him" replaced by the value of `repText'.
(The string value of `text' will remain _unchanged_. String values
are _immutable_ in ECMAScript implementations.)
A word, on the other hand, is usually defined as a substring delimited by
the start of input (or line), the end of input (or line), and/or non-word
characters (such as white-space). Whereas a word character is usually
defined (and so by the `\w' and `\b' escape sequences in ECMAScript) to
include the alphanumeric ASCII characters and the `_' (underscore)
character (/\w/ ~ /[0-9A-Za-z_]/). That is, the return value of
"foobarbaz".replace(/bar/gi, "bla")
is
"fooblabaz"
whereas "bar" surely cannot be considered a word in any sense, but a
_substring_ instead.
6. Reconsider your use of the term "RegExp object". There is only one
`RegExp' object in (an) ECMAScript (implementation). Objects created
using the `RegExp' constructor/factory object (i. e., `new RegExp(…)' or
`RegExp(…)') are thus called "RegExp _instances_' in the pertaining
Editions of the ECMAScript Language Specification. See for example
Edition 5, section 15.10.7.
7. window.location.replace(…), i. e. the replace(…) method of the location
object as referred to by the `location' property of window objects has
nothing to do with all this. Location objects are part of the
AOM (Application Object Model) API provided by the host environment
(a web browser, usually), not any programming language (anymore).
If you think that method should be mentioned in that article at all, make
it very clear that this method _has nothing to do_ with the method that
you discussed previously, and why, so that you do not to mislead your
readers.
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