[js] create proper closure for Array.push (closes #1997)

See #1997