Results 1 to 6 of 6

Thread: about Ext.combine's problem

  1. #1

    Default about Ext.combine's problem

    Code:
    combine : function(){
                var as = arguments, l = as.length, r = [];	
                for(var i = 0; i < l; i++){
                    var a = as[i];
                    if(a instanceof Array){				
                        r = r.concat(a);
                    }else if(a.length !== undefined && !a.substr){
                        r = r.concat(Array.prototype.slice.call(a,0));
                    }else{
                        r.push(a);
                    }
                }
                return r;
            }
    Code:
    if(a.length !== undefined && !a.substr)){
           r = r.concat(Array.prototype.slice.call(a,0));
    }
    if it's true,type of a is Function objects...what's purpose of the statement(if(a.length !== undefined && !a.substr))?Array r need combine a Function objects?such as Ext.combine(function(b,c,d){var ss="test"},result is ",,",I can't understand effect of the "if(a.length !== undefined && !a.substr))"

  2. #2
    Sencha User hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,966

    Thumbs up

    Code:
    if(a.length !== undefined && !a.substr))
    is a way of asserting 'a' as an array. (has length, but is not a string (a.substr test)
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  3. #3

    Default

    A is an Array? ....if a is an Array or subclass of Array it is performed never,
    because "if a instanceof Array" is performed first ,so a is objects of Function

    Code:
    if(a instanceof Array){				
          r = r.concat(a);
     }else if(a.length !== undefined && !a.substr){
    }

  4. #4
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,239

    Default

    Just guessing, but perhaps some browsers don't support instanceOf correctly, so the second check would take care of that.

  5. #5

    Default

    this explanation is reasonable! it's possible,which browser don't support instanceOf operator
    do you know,evant?

  6. #6

    Default Doubt

    in my opinion, only Function type meet this conditions, For Example
    var text = function( a, b, c, d) {
    returb a+b+c+d;
    }

    text.length is defined but text.substr is undefined
    Last edited by Pietist; 8 Apr 2010 at 12:05 AM. Reason: because of new thought

Posting Permissions

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