Skip to content

Commit

Permalink
Created isDefined( obj ) and isFunction( obj ) to wrap is( obj, 'unde…
Browse files Browse the repository at this point in the history
…fined' || 'function' ) to explore code weight. Turns out this is slightly more minified and more minified + gzipped than the single is( o, t ) variation.
  • Loading branch information
Phil Dokas committed Oct 26, 2010
1 parent 6b6b919 commit d125248
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions modernizr.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ window.Modernizr = (function(window,document,undefined){
}
if (element.setAttribute && element.removeAttribute) {
element.setAttribute(eventName, '');
isSupported = is(element[eventName], 'function');
isSupported = isFunction(element[eventName]);

// If property was created, "remove it" (by setting value to `undefined`)
if (!is(element[eventName], 'undefined')) {
if (isDefined(element[eventName])) {
element[eventName] = undefined;
}
element.removeAttribute(eventName);
Expand All @@ -167,14 +167,14 @@ window.Modernizr = (function(window,document,undefined){

// hasOwnProperty shim by kangax needed for Safari 2.0 support
var _hasOwnProperty = ({}).hasOwnProperty, hasOwnProperty;
if (!is(_hasOwnProperty, 'undefined') && !is(_hasOwnProperty.call, 'undefined')) {
if (isDefined(_hasOwnProperty) && isDefined(_hasOwnProperty.call)) {
hasOwnProperty = function (object, property) {
return _hasOwnProperty.call(object, property);
};
}
else {
hasOwnProperty = function (object, property) { /* yes, this can give false positives/negatives, but most of the time we don't care about those */
return ((property in object) && is(object.constructor.prototype[property], 'undefined'));
return ((property in object) && !isDefined(object.constructor.prototype[property]));
};
}

Expand All @@ -199,6 +199,20 @@ window.Modernizr = (function(window,document,undefined){
return typeof obj === type;
}

/**
* isDefined returns a boolean for if typeof obj is 'undefined'.
*/
function isDefined( obj ) {
return !is(obj, 'undefined');
}

/**
* isFunction returns a boolean for if typeof obj is 'function'.
*/
function isFunction( obj ) {
return is(obj, 'function');
}

/**
* contains returns a boolean for if substr is found within str.
*/
Expand Down Expand Up @@ -292,7 +306,7 @@ window.Modernizr = (function(window,document,undefined){
};

tests['canvastext'] = function() {
return !!(ret['canvas'] && is(document.createElement( 'canvas' ).getContext('2d').fillText, 'function'));
return !!(ret['canvas'] && isFunction(document.createElement( 'canvas' ).getContext('2d').fillText));
};


Expand Down

0 comments on commit d125248

Please sign in to comment.