Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Keyword 'this' | Classes & Objects
Object-Oriented Programming in JavaScript
セクション 1.  5
single

single

bookKeyword 'this'

メニューを表示するにはスワイプしてください

You can refer to the attributes not only outside the class but inside, too, for example, inside methods. To do that, use this keyword. this is like a name of object, but it means the current object, i. e. it refers to the global object.

Let's change current age of the student each time we call happyBirthday() function, and print it:

123456789101112131415
class Student{ name = 'June'; university = 'MIT'; age = 18; gpa; sleep(){ console.log('I am sleeping right now!') } happyBirthday(){ this.age += 1; console.log('Today is my birthday! I am', this.age, 'yrs old!'); } }
copy
タスク

スワイプしてコーディングを開始

Modify happyBirthday() function: output info about new age and about name of the student. After that, create an object of class Student, and call this method three times to see what happens with age.

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  5
single

single

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt