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