Results 1 to 5 of 5

Thread: Is Ext.isFunction completely reliable?

  1. #1
    Sencha User
    Join Date
    Mar 2010
    Posts
    39
    Answers
    2

    Default Answered: Is Ext.isFunction completely reliable?

    I had posted this question on the doc page before I noticed an admonition not to post questions about code or usage so I'm repeating it here:

    In "Secrets of the JavaScript Ninja", the following caveat is given to their implementation of isFunction which uses a technique similar to the one Ext.isFunction uses:

    "There is one notable exception, however. (Isnt there always?) Internet Explorer reports methods of DOM elements with a type of object, like so: typeof domNode.getAttribute == "object" and typeof inputElem.focus == "object". So this particular technique doesnt cover this case."


    I don't see where this exception is accounted for in the Ext.isFunction code. Am I missing something or does this caveat apply here as well?

    Thanks

  2. I looked into this before. If I remember correctly it can't identify those IE functions as functions. To the best of my knowledge there is no safe and reliable way to detect all such functions.

    Also, it should be noted that for many of them they don't behave exactly like functions. While they are invokable they don't have all the other properties you might expect a normal function to have. So to some extent it depends on your definition of a function as to whether they should even count.

    In practice I've never seen this cause a real application any problems.

  3. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379
    Answers
    3997

    Default

    I haven't had any issues but usually don't have to check if something is a function. Here is what the isFunction looks like:

    Code:
            isFunction:
            // Safari 3.x and 4.x returns 'function' for typeof <NodeList>, hence we need to fall back to using
            // Object.prototype.toString (slower)
            (typeof document !== 'undefined' && typeof document.getElementsByTagName('body') === 'function') ? function(value) {
                return toString.call(value) === '[object Function]';
            } : function(value) {
                return typeof value === 'function';
            }
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  4. #3
    Sencha User
    Join Date
    Mar 2010
    Posts
    39
    Answers
    2

    Default

    Thanks for the response Mitchell.


    I had already looked at the code as I noted in my post.


    I was actually wondering if the following caveat quoted from "Secrets of the JavaScript Ninja" regarding their implementation of isFunction is addressed in Ext.isFunction:


    "There is one notable exception, however. (Isnt there always?) Internet Explorer reports methods of DOM elements with a type of object, like so: typeof domNode.getAttribute == "object" and typeof inputElem.focus == "object". So this particular technique doesnt cover this case."


    I don't see from looking at the code where it is addressed.

  5. #4
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585

    Default

    I looked into this before. If I remember correctly it can't identify those IE functions as functions. To the best of my knowledge there is no safe and reliable way to detect all such functions.

    Also, it should be noted that for many of them they don't behave exactly like functions. While they are invokable they don't have all the other properties you might expect a normal function to have. So to some extent it depends on your definition of a function as to whether they should even count.

    In practice I've never seen this cause a real application any problems.

  6. #5
    Sencha User
    Join Date
    Mar 2010
    Posts
    39
    Answers
    2

    Default

    Thanks skirtle. I hear what you and Mitchell are saying about not having encountered problems with this. I still think that it should be noted in the documentation for completeness and also so people like me aren't posing pesky questions like this.

    I'll go ahead and post another comment on the doc page linking back to this post to see if someone will be kind enough to update it.

    Thanks again.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •