In this code:
function SomeObject (param) { this.param = param = param || {}; }
Two separate assignments are performed: one for the local variable param (the actual argument of the function), and the other for the this property, no matter what happens. These two different destination goals are not the same. (Of course, they will get the same value, but they are two separate places to place the values.)
In my experience, itβs much more common to have a simple default set for the parameter itself:
function whatever(x) { x = x || {};
However, there is nothing wrong with assigning to an object, if that makes sense.
source share