Simple function locking in javascript