Javascript - A First Look at this
Code Life
By Pierre Marsaa
A Method That Knows Its Object
In the last chapter, the bag's methods wrote bag.items. It works, but the method depends on the variable name bag. Rename the variable and everything breaks. There's a better way:
↗️
Loading editor...
↶
↷
Inside a method, this means the object the method was called on. this.name is the name of that object. The method doesn't need to know the variable is called zap.
Verify