JavaScript: Class handling functions