Fixed #2072 optimize performance for javascript

Optimize performance for javascript