Using var a
in the function means that a
will always be private. Since importScripts adds to the global scope, JS prefers to access the more localized a
in the function that posts a
. You can post self.a
instead, which shall be 6, as you expected.
EDIT: Someone recently asked me about this in person, so I made a demo to clarify the behaviour: http://pagedemos.com/importscript/