Javascript default parameter with extra assignment -


in javascript, see code following set default parameter when don't care ignore falsey values.

function someobject (param) {     this.param = param || {}; } 

occasionally though, when reading code, i'll come across following variation:

function someobject (param) {     this.param = param = param || {}; } 

can explain me use case this?

in code:

function someobject (param) {     this.param = param = param || {}; } 

two separate assignments made: 1 param local variable (the actual argument function) , 1 property of this, whatever happens be. 2 different assignment targets not same. (they'll same value of course, they're 2 separate places put values.)

in experience, it's far more common see simple default established parameter itself:

function whatever(x) {   x = x || {}; 

there's nothing wrong, however, assigning object property when makes sense.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -