Search code examples
javascriptclosuresvariable-assignmentassignment-operator

Shortcut syntax for clearing JavaScript closures


Based on the chaining rules for JavaScript, I have been using the following shortcut syntax to clear closure variables:

//Clear closure variables....
a=b=c=d=e=f=null;

For context, the situation might be:

// variables a,b,c,d,e are defined somewhere up here.

doSomething(function callback() {
   // Do a bunch of work with a,b,c,d,e
   // Now clear variables
   a=b=c=d=e=null;
});

Is this a reasonable way to set a bunch of variables to null concisely?


Solution

  • Yes, it totally is.

    Altough I prefer spaces around assignment operators.

    And you hardly ever really need to null out closure variables. If you work on such advanced stuff, chained assignments are a minor concern.