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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -