Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9647: shorter_type_check_definitions.diff

File shorter_type_check_definitions.diff, 0.8 kB (added by kangax, 10 months ago)
  • base.js

    old new  
    125125    return object && object.constructor === Array; 
    126126  }, 
    127127   
    128   isFunction: function(object) { 
    129     return typeof object == "function"; 
    130   }, 
    131    
    132   isString: function(object) { 
    133     return typeof object == "string"; 
    134   }, 
    135    
    136   isNumber: function(object) { 
    137     return typeof object == "number"; 
    138   }, 
    139    
    140   isUndefined: function(object) { 
    141     return typeof object == "undefined"; 
    142   } 
     128  $w('function string number undefined').each(function(type){ 
     129    Object['is' + type.capitalize()] = function(object) { 
     130      return typeof object == type; 
     131    } 
     132  }) 
    143133}); 
    144134 
    145135Object.extend(Function.prototype, {