From: David Mark on
I have posted a new primer related to host objects and feature
detection/testing.

http://www.cinsoft.net/host.html

I think that about sums up the progress (and lack thereof) of the last
few years. You might think Resig is the JS Superman (or Chuck
Norris[1]), but I'm telling you he has a David Mark nightlight. :)

[1] http://benalman.com/news/2009/12/john-resig-javascripts-chuck-norris/
From: Thomas 'PointedEars' Lahn on
David Mark wrote:

> I have posted a new primer related to host objects and feature
> detection/testing.
>
> http://www.cinsoft.net/host.html
>
> I think that about sums up the progress (and lack thereof) of the last
> few years.

ISTM the RegExp is borken:

var reFeaturedMethod = new RegExp('^function|object$', 'i');

It matches case-insensitive either "function" at the begin of input or
"object" at the end, when it should match case-insensitive an input that is
either "function" or "object":

var reFeaturedMethod = new RegExp('^(function|object)$', 'i');

Furthermore, AISB,

return !!((reFeaturedMethod.test(t) && o[m]) || t == 'unknown');

becomes more efficient when writing

return !!(t == 'unknown' || (reFeaturedMethod.test(t) && o[m]));

The double negation to cast to boolean is a matter of taste; I do not think
it is necessary, because one possible result is a boolean already and the
other has been proven by this that it can be used in a type-converting
test.

Either the identifier or the code of isHostObjectProperty() does not make
sense.

I am going to comment on the rest later.


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
From: David Mark on
Thomas 'PointedEars' Lahn wrote:
> David Mark wrote:
>
>> I have posted a new primer related to host objects and feature
>> detection/testing.
>>
>> http://www.cinsoft.net/host.html
>>
>> I think that about sums up the progress (and lack thereof) of the last
>> few years.
>
> ISTM the RegExp is borken:
>
> var reFeaturedMethod = new RegExp('^function|object$', 'i');
>
> It matches case-insensitive either "function" at the begin of input or
> "object" at the end, when it should match case-insensitive an input that is
> either "function" or "object":

You got it. That reflects either sloppiness or cluelessness on my part
at the time I wrote that line (first one I wrote for My Library). :)
it's fixed in the pasted example and the library. Thanks!

And BTW, I forgot to mention your isMethodType as the inspiration for
that function. I'll add that when I have a chance. I need to explain a
little bit more about that one anyway.

>
> var reFeaturedMethod = new RegExp('^(function|object)$', 'i');
>
> Furthermore, AISB,
>
> return !!((reFeaturedMethod.test(t) && o[m]) || t == 'unknown');
>
> becomes more efficient when writing
>
> return !!(t == 'unknown' || (reFeaturedMethod.test(t) && o[m]));

Could be. I'm not sure.

>
> The double negation to cast to boolean is a matter of taste; I do not think
> it is necessary, because one possible result is a boolean already and the
> other has been proven by this that it can be used in a type-converting
> test.

I just like for the function to return a boolean for all cases.

>
> Either the identifier or the code of isHostObjectProperty() does not make
> sense.

The identifier is not particularly descriptive. Read the description
carefully. There is an assertion you must make as part of the contract
with that (and isHostMethod). Remember that some objects (e.g.
childNodes) can have typeof "function". You are asserting that you will
do something other than call it, which is why the "unknown" types are
excluded. I need to flesh out the explanation, which was copied
straight from the skeletal library documentation.

>
> I am going to comment on the rest later.

Comments welcome! :)
From: David Mark on
David Mark wrote:
> Thomas 'PointedEars' Lahn wrote:
>> David Mark wrote:
>>
>>> I have posted a new primer related to host objects and feature
>>> detection/testing.
>>>
>>> http://www.cinsoft.net/host.html
>>>
>>> I think that about sums up the progress (and lack thereof) of the last
>>> few years.
>> ISTM the RegExp is borken:
>>
>> var reFeaturedMethod = new RegExp('^function|object$', 'i');
>>
>> It matches case-insensitive either "function" at the begin of input or
>> "object" at the end, when it should match case-insensitive an input that is
>> either "function" or "object":
>
> You got it. That reflects either sloppiness or cluelessness on my part
> at the time I wrote that line (first one I wrote for My Library). :)
> it's fixed in the pasted example and the library. Thanks!
>
> And BTW, I forgot to mention your isMethodType as the inspiration for
> that function. I'll add that when I have a chance. I need to explain a
> little bit more about that one anyway.

Now mentioned, as well as the blog post that followed Peter's site.
From: Garrett Smith on
Thomas 'PointedEars' Lahn wrote:
> David Mark wrote:
>
>> I have posted a new primer related to host objects and feature
>> detection/testing.

[...]

>
> ISTM the RegExp is borken:
>
> var reFeaturedMethod = new RegExp('^function|object$', 'i');
>
> It matches case-insensitive either "function" at the begin of input or
> "object" at the end, when it should match case-insensitive an input that is
> either "function" or "object":
>
> var reFeaturedMethod = new RegExp('^(function|object)$', 'i');
>

A Literal would be shorter and would stay cached:

/^(?:func|obj)/;

> Furthermore, AISB,
>
> return !!((reFeaturedMethod.test(t) && o[m]) || t == 'unknown');
>
> becomes more efficient when writing
>
> return !!(t == 'unknown' || (reFeaturedMethod.test(t) && o[m]));
>
> The double negation to cast to boolean is a matter of taste; I do not think
> it is necessary, because one possible result is a boolean already and the
> other has been proven by this that it can be used in a type-converting
> test.
>
Double negation on a boolean is pointless. However, `o[m]` should not be
a boolean; it should be a function or an object.

Caveats:
Object `o` could be callable and falsish, such as nonstandard callable
"document.all".

Object `o` could be the `item` method, for which typeof will result
"string" in IE. This would result in isHostMethod returning false.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/