Permalink
Browse files

improve the way undefined is used in a few places

  • Loading branch information...
1 parent dea8af9 commit bc7fe4c589cf2498f35543f181783b1f0ed57284 @vikstrous committed Oct 20, 2012
Showing with 3 additions and 5 deletions.
  1. +3 −5 src/zepto.js
View
@@ -54,7 +54,7 @@ var Zepto = (function() {
function isArray(value) { return value instanceof Array }
function likeArray(obj) { return typeof obj.length == 'number' }
- function compact(array) { return filter.call(array, function(item){ return item !== undefined && item !== null }) }
+ function compact(array) { return filter.call(array, function(item){ return item != null }) } /* Note: null and undefined are == equal */
function flatten(array) { return array.length > 0 ? $.fn.concat.apply([], array) : array }
camelize = function(str){ return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' }) }
function dasherize(str) {
@@ -534,7 +534,7 @@ var Zepto = (function() {
},
prop: function(name, value){
return (value === undefined) ?
- (this[0] ? this[0][name] : undefined) :
+ (this[0] && this[0][name]) :
this.each(function(idx){
this[name] = funcArg(this, value, idx, this[name])
})
@@ -565,9 +565,7 @@ var Zepto = (function() {
css: function(property, value){
if (arguments.length < 2 && typeof property == 'string')
return (
- this.length == 0
- ? undefined
- : this[0].style[camelize(property)] || getComputedStyle(this[0], '').getPropertyValue(property))
+ this[0] && this[0].style[camelize(property)] || getComputedStyle(this[0], '').getPropertyValue(property))
var css = ''
for (key in property)

0 comments on commit bc7fe4c

Please sign in to comment.