Skip to content

Commit 761201e

Browse files
committed
Shave off a few bytes by avoiding arguments.length checks
Closes madrobby#350, closes madrobby#931
1 parent 097c883 commit 761201e

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/data.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
$.each(name, function(key, value){ setData(node, key, value) })
5353
}) :
5454
// get value from first element
55-
this.length == 0 ? undefined : getData(this[0], name) :
55+
(0 in this ? getData(this[0], name) : undefined) :
5656
// set value on all elements
5757
this.each(function(){ setData(this, name, value) })
5858
}

src/zepto.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -585,25 +585,25 @@ var Zepto = (function() {
585585
prev: function(selector){ return $(this.pluck('previousElementSibling')).filter(selector || '*') },
586586
next: function(selector){ return $(this.pluck('nextElementSibling')).filter(selector || '*') },
587587
html: function(html){
588-
return arguments.length === 0 ?
589-
(this.length > 0 ? this[0].innerHTML : null) :
588+
return 0 in arguments ?
590589
this.each(function(idx){
591590
var originHtml = this.innerHTML
592591
$(this).empty().append( funcArg(this, html, idx, originHtml) )
593-
})
592+
}) :
593+
(0 in this ? this[0].innerHTML : null)
594594
},
595595
text: function(text){
596-
return arguments.length === 0 ?
597-
(this.length > 0 ? this[0].textContent : null) :
596+
return 0 in arguments ?
598597
this.each(function(idx){
599598
var newText = funcArg(this, text, idx, this.textContent)
600599
this.textContent = newText == null ? '' : ''+newText
601-
})
600+
}) :
601+
(0 in this ? this[0].textContent : null)
602602
},
603603
attr: function(name, value){
604604
var result
605605
return (typeof name == 'string' && value === undefined) ?
606-
(this.length == 0 || this[0].nodeType !== 1 ? undefined :
606+
(!this.length || this[0].nodeType !== 1 ? undefined :
607607
(!(result = this[0].getAttribute(name)) && name in this[0]) ? this[0][name] : result
608608
) :
609609
this.each(function(idx){
@@ -628,14 +628,14 @@ var Zepto = (function() {
628628
return data !== null ? deserializeValue(data) : undefined
629629
},
630630
val: function(value){
631-
return arguments.length === 0 ?
631+
return 0 in arguments ?
632+
this.each(function(idx){
633+
this.value = funcArg(this, value, idx, this.value)
634+
}) :
632635
(this[0] && (this[0].multiple ?
633636
$(this[0]).find('option').filter(function(){ return this.selected }).pluck('value') :
634637
this[0].value)
635-
) :
636-
this.each(function(idx){
637-
this.value = funcArg(this, value, idx, this.value)
638-
})
638+
)
639639
},
640640
offset: function(coordinates){
641641
if (coordinates) return this.each(function(index){
@@ -650,7 +650,7 @@ var Zepto = (function() {
650650
if ($this.css('position') == 'static') props['position'] = 'relative'
651651
$this.css(props)
652652
})
653-
if (this.length==0) return null
653+
if (!this.length) return null
654654
var obj = this[0].getBoundingClientRect()
655655
return {
656656
left: obj.left + window.pageXOffset,

0 commit comments

Comments
 (0)