Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upAvoid reassign parameters #818
Comments
This comment has been minimized.
This comment has been minimized.
|
Ecosystem breakage isn't going to be pleasant. |
dcousens
added
the
enhancement
label
Mar 10, 2017
This comment has been minimized.
This comment has been minimized.
|
Huge no no on this one, this would make using standard impossible for me.
Default params using `foo = foo || {}` is staple. Also using arguments is a
common thing to do
…On Fri, Mar 10, 2017, 14:54 Daniel Cousens ***@***.***> wrote:
Ecosystem breakage isn't going to be pleasant.
And honestly, you could just as easily encourage people *not* to use the
arguments object except in limited circumstances.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#818 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACWleh8QP8EgS0ZnQWaCy0TYU_5a6Ewdks5rkVX3gaJpZM4MZE3M>
.
|
This comment has been minimized.
This comment has been minimized.
|
@yoshuawuyts is right that function foo (opts) {
opts = Object.assign({
default1: true,
default2: 'cool string'
}, opts)
}Also, using function foo (...args) {
}I'd prefer to pass on this rule, even though I agree at a high-level that it sounds desirable. It's just not practical in the real-world. |
feross
closed this
Mar 10, 2017
This comment has been minimized.
This comment has been minimized.
|
@feross I think if you could avoid |
This comment has been minimized.
This comment has been minimized.
|
@dcousens yeah I think so, although it's very common - just in the last week I've written 2 new modules built entirely around this. In the example below there's no escaping using // written just for show, idk there might be bugs but yeah.
Emitter.prototype.emit = function (eventName) {
var event = null
var args = []
for (var i = arguments.length - 1; i >= 1; --i) args[i] = arguments[i]
var events = this._events[eventName]
if (!events) return
for (var j = events.length - 1; i >= 0; --i) {
event = events[j]
event.apply(event, args)
}
}
Like with most things there's probably fancy ways to write this using new language additions, but I'd rather we allow people (like me |
This comment has been minimized.
This comment has been minimized.
Sure thing. Wasn't trying to enforce that on folks. I was just saying that I'm not too worried about Also, most functions that use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Maybe that is something we could look into enforcing? |

foisonocean commentedMar 10, 2017
I think it's very useful: http://eslint.org/docs/rules/no-param-reassign.html