gruss molily,
Nun mal langsam mit den jungen Pferden.
In SELFHTML steht vieles nicht drin, deshalb ist das Fehlende noch längst
nicht gleichermaßen empfehlenswert. new RegExp ist ECMAScript-standardisiert,
search(String) hingegen ist in keiner Spezifikation auch nur erwähnt
(man korrigiere mich).
ok - Du hast es so gewollt:
<blockquote lang="en" cite="[link:http://www.ecma-international.org/publications/standards/Ecma-262.htm]">
15\.5.4.12 String.prototype.search (regexp)
If regexp is not an object whose [[Class]] property is "RegExp",
it is replaced with the result of the expression new RegExp(regexp).
</blockquote>
----------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
dieser fall wird demzufolge mit einem umwandlungsautomatismus abgefangen.
<blockquote lang="en" cite="[link:http://www.ecma-international.org/publications/standards/Ecma-262.htm]">
Let string denote the result of converting the this value to a string.
The value string is searched from its beginning for an occurrence of
the regular expression pattern regexp. The result is a number indicating
the offset within the string where the pattern matched, or –1 if there
was no match.
NOTE 1
This method ignores the lastIndex and global properties of regexp. The
lastIndex property of regexp is left unchanged.
NOTE 2
The search 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.
</blockquote>
----------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
wobei NOTE 2 noch viel beeindruckender ist, als "kann"-bestimmung aber offiziell
und auch offensichtlich noch fuer keinen browser umgesetzt wurde.
(function () {
alert("ECMA 262 - 15.5.4.12 - NOTE 2");
alert(arguments.callee.search);
alert((new Object()).search);
})();
Wenn man search() also einen String übergibt, sollte man zur Kenntnis nehmen,
dass das weder gültiges ECMAScript, noch gültiges Microsoft JScript, noch
gültiges Netscape JavaScript ist. Das heißt, man kann sich auch nicht darauf
verlassen, dass irgendein unbekannter JavaScript/ECMAScript-Interpreter den
Code korrekt ausführt.
siehe oben.
by(t)e by(t)e - peterS. - pseliger@gmx.net
»Because objects in JavaScript are so flexible, you will want to think differently about class hierarchies.
Deep hierarchies are inappropriate. Shallow hierarchies are efficient and expressive.« - Douglas Crockford
ie:( fl:) br:> va:( ls:& fo:) rl:| n3;} n4:} ss:} de:µ js:} mo:? zu:]