madrobby/zepto — Issue #350: Make optional argument checks with `0 in arguments`
Author: rafBM
Created: 2011-12-03 20:20:04+00:00
State: open

Is there a reason why all checks for optional arguments in getter/setter methods are made like `arg === undefined` rather than `arguments.length > 0` or `0 in arguments`?

It can produce unexpected results when the argument you pass is an object property that happens to be `undefined`.

```js
var myData = [
{
mandatoryProp: 'foo',
optionalProp: 'bar'
},
{
mandatoryProp: 'baz'
}
]

$('li').each(function(i) {
$(this).find('span.mandatory-prop').html(myData[i].mandatoryProp)
$(this).find('span.optional-prop').html(myData[i].optionalProp).addClass('i-can-haz')
// no method `.addClass` for String because `.html` acted as a getter
})
```

In the case of `.html(undefined)`, I would rather have it act like `.html('')`.

I think it’s a very likely issue. If you agree I’m willing to fix it.