Re: Is jQuery worth a second look?



Oltmans wrote:
On Sep 30, 6:38 pm, "Thomas 'PointedEars' Lahn" <PointedE...@xxxxxx>
wrote:
kangax wrote:
dhtml wrote:
isFunction - still uses function decompilation. Kangax posted on
es-discuss that that was changed but I still see the isFunction in the
latest 1.2.6.
Garrett,
their trunk is using `instanceof` [1].
Irrelevant, except that it shows their cluelessness.


Why using "instanceof" considered to be not so good? Can you please
explain it to me with a few examples? That will be highly appreciated.


Instanceof won't work like you want it to across frames. This is because self.Function != frames[0].Function.

frames[0].fun instanceof Function will return false across frames.
Two documents example:
document1.html
myframe.html:


document1.html:
<body>
<iframe src="myframe.html"></iframe>

<script>
onload = function() {
var f = frames[0].fun;
document.write(['<pre>',f instanceof Function, f].join('\n'));
document.close();
};
</script>

</body>


myframe.html:
<script>
function fun() {}
</script>

Result:
false
function fun() {
}

So we can see that instanceof won't work across frames like you'd want it to, and the isFunction uses instance of.

Garrett
.



Relevant Pages

  • Re: Is jQuery worth a second look?
    ... Instanceof won't work like you want it to across frames. ... function fun() ... and the isFunction uses instance of. ...
    (comp.lang.javascript)
  • Re: calling a function whose name is passed as an argument
    ... instanceof and isPrototypeOf could be used. ... That's what David spent many long replies trying to explain to Thomas, who seemed to not understand the intent of David's isFunction. ... isFunction isn't necessary and typeof is really all you need. ... There is no way to determine if a Host object is callable, other than to try and call it, though that may result in Error. ...
    (comp.lang.javascript)
  • Re: calling a function whose name is passed as an argument
    ... I was almost going to recommend the jQuery 'isFunction' function here, ... because (you are contradicting yourself in the ... So testing with either instanceof or typeof is only suitable if the ...
    (comp.lang.javascript)
  • Re: Is jQuery worth a second look?
    ... es-discuss that that was changed but I still see the isFunction in the ... their trunk is using `instanceof`. ...
    (comp.lang.javascript)