Prev: A practical exercise: fighting maskons
Next: FAQ Topic - How do I get a jsp/php variable into client-side javascript? (2009-11-10)
From: Thomas 'PointedEars' Lahn on 11 Nov 2009 12:55 kangax wrote: > Garrett Smith wrote: >> That's odd. Seems in Tracemonkey, a RegExp is callable without >> implementing [[Call]], or ? A bug in there syntax extension, due >> to internal typechecking for RegExp, as: >> typeof /a/ The result of the `typeof' operation has no relevance to the implementation of the [[Call]] property of its operand. > Yes, from what I remember, Mozilla makes regex objects callable without > actually giving them [[Call]]. How can you possibly tell? If it does not implement [[Call]] it must throw a TypeError, but it does not do that in TraceMonkey 1.8.1 (Iceweasel 3.5.4). So we have to assume it does implement [[Call]]. `/x/(s)' appears to return an Array of the matches of the Regular Expression `/x/' in the string value `s' there, as if by the expression `/x/.exec(s)'. And no, that is _not_ "a clear violation" of ECMA-262 Ed. 3, but at least a syntax extension supported the Specification itself. Indeed, I would like to see it formally specified in Edition 5. 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
From: Thomas 'PointedEars' Lahn on 11 Nov 2009 13:00 Thomas 'PointedEars' Lahn wrote: > `/x/(s)' appears to return an Array of the matches of the Regular > Expression `/x/' in the string value `s' [in JavaScript 1.8.1], as if by > the expression `/x/.exec(s)'. > > And no, that is _not_ "a clear violation" of ECMA-262 Ed. 3, but at least > a syntax extension supported the Specification itself. Indeed, I would > like to see it formally specified in Edition 5. Sorry, Richard, I misunderstood what you were saying. Full ACK now. PointedEars -- realism: HTML 4.01 Strict evangelism: XHTML 1.0 Strict madness: XHTML 1.1 as application/xhtml+xml -- Bjoern Hoehrmann
From: Garrett Smith on 11 Nov 2009 13:25 Richard Cornford wrote: > kangax wrote: >> Garrett Smith wrote: > <snip> [...] > A (one of the many) bugbears of - isFunction - Firefox's response to:- > > var x = document.createElement('OBJECT'); > > - which, when tested with - typeof - returns 'function'. This is seen as > incorrect, e.g.:- > > <URL: http://jsninja.com/Functions#Function_Type > > That code was reviewed here over a year ago and was changed in jQuery: | isFunction: function( obj ) { | return toString.call(obj) === "[object Function]"; | } What surprises me is that wiki document was modified very recently: # (cur) (last) 22:22, 28 September 2009 Jsninja (Talk | contribs) m (Protected "Functions" [edit=sysop:move=sysop]) (undo) The document also states: | var ninja = function myNinja(){ | assert( ninja == myNinja, | "This function is named two things - at once!" ); | }; | ninja(); | assert( typeof myNinja == "undefined", | "But myNinja isn't defined outside of the function." ); | | This brings up the most important point: Anonymous functions can be | named but those names are only visible within the functions | themselves. That statement is true in the spec, but not in reality, and if the example had been run in IE, that would have been realized. This has been discussed here a lot. Juriy's NFE article goes into depth on this as well. [...] -- Garrett comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Peter Michaux on 11 Nov 2009 13:31 On Nov 11, 11:40 am, Thomas 'PointedEars' Lahn <PointedE...(a)web.de> wrote: > Peter Michaux wrote: > > Thomas 'PointedEars' Lahn wrote: > >> Peter Michaux wrote: > >> > On Nov 9, 2:41 pm, Asen Bozhilov <asen.bozhi...(a)gmail.com> wrote: > >> >> | 7.6 Identifiers > >> >> | This standard specifies one departure from the grammar given in the > >> >> | Unicode standard: The dollar sign ($) and the underscore (_) are > >> >> | permitted anywhere in an identifier. The dollar sign is intended for > >> >> | use only in mechanically generated code. > > >> > I believe this statement is gone from the proposed ECMAScript 5 and if > >> > so I think it is good they removed it. > > >> Well, I for one do not want to see code like the following spreading > >> around: > > >> <?php > >> $bar = 'baz'; > >> $foo = 'bar'; > >> echo <<<JS > >> \$foo.\$ = '{$$foo}'; > >> JS; > >> ?> > > >> Do you? > > > No. I think that I would not have allowed '$' to be part of identifier > > in the first place. > > Then I do not understand your opinion above. A recommendation against, > as it is in Edition 3, is a step in the right direction in that sense; > a missing recommendation against, as it could be in Edition 5, is not. If '$' is allowed then just allow it without any qualification or any advice about how it should be used unless such qualification is enforced by the language. Such wimpy advice as given in ES3 will be and has been ignored as programmers will always do anything they can get away with doing...so don't bother with the wimpy advice as part of the language spec in the first place. Imagine they had given indenting advice (e.g. four spaces, no tabs). That would have been promptly ignored also if two spaces and tabs were allowed. Peter
From: Asen Bozhilov on 11 Nov 2009 14:27
Richard Cornford wrote: > If you can give a clear definition > of what 'being a function' is then you are probably in a position to > either design and effective - isFunction - method, or to declare the > determination untestable and so give up the attempt. For my `function' is `object' who [[Prototype]] and Function.prototype referred to same `object'. If i want to test someone `object' for `isFunction' i ever used `instanceof'. if (f instanceof Function) { f.call; f.apply; f.dummyEnumPropertyInPrototypeChain; } Approach which compare internal [[Class]] property with string literal '[object Function]'. I don't think proper name of that approach is `isFunction' especially in browser environment, where supports cross frame scripting. e.g. Function.prototype.bind = function(){}; var f = window.frames[0].f; if (Object.prototype.toString.call(f) == '[object Function]') //true { f.bind(); //throw f.bind is not a function } |