课程: Level Up: JavaScript

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Private object

Private object

(lively game music) - [Instructor] JavaScript symbols were a new primitive data type introduced with ES6. Every value returned from a symbol is unique, meaning that we can use them as identifiers for object properties. In this challenge, you will create a user object that has three properties: username, password, and age. Using JavaScript symbols, ensure that username and password are private fields on the user character. This means they shouldn't be accessible by calling user.username or user.password. Pause a video here, develop your solution and when you're ready, come back and I'll walk you through how I solve the challenge. (lively music) Let's first create two symbols, one for username and one for password. Now let's create our user object. I'll enter some fake information for us to test out. If we console.log user.username, and user.password, we should see the values, emmabostian and 1234566 being logged to the…

内容