Incorrect javascript method scope