9. Please help with "Nouns & Verbs Together"


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-9Sgpi/2/1?curriculum_id=506324b3a7dffd00020bf661


The code is default and is done by codecademy but I'm not completely understanding something; phonebookEntry.phone() calls Oxnard b/c Oxnard is the only name and number in the object right? Or is it because phonebookEntry is a method only for Oxnard?


var phonebookEntry = {};

phonebookEntry.name = 'Oxnard Montalvo';
phonebookEntry.number = '(555) 555-5555';
phonebookEntry.phone = function() {
  console.log('Calling ' + this.name + ' at ' + this.number + '...');
};

phonebookEntry.phone();


#2

@kevin.reliancegmail this was not because oxnard was the only name in the javascript written by codecademy but is due to the "this" pointer.
When it says this.name it says the name currently defined by the instance of the object. To make things simpler i will say this pointer is used to point to the latest instance of the object .
Say for example had you also defined something like " phonebookentry.name = 'a' " then the compiler would have printed "Calling a at (555) 555-5555" since this was the latest instance of the object.
Hope this helped :smile:
If satisfied mark as a solution.. :wink:


#3

Got it. So the most recent phonebookEntry.name would have come up, right? Thanks, Ronit.


#4

@kevin.reliancegmail yes the most recent entry or rather object instance
would come up..
Most welcome :wink:

Ronit Gaikwad
kevin.reliancegmail
https://discuss.codecademy.com/users/kevin.reliancegmail
September 1

Got it. So the most recent phonebookEntry.name would have come up, right?
Thanks, Ronit.

Visit Topic


or reply to this email to respond.
In Reply To
ronit1710 https://discuss.codecademy.com/users/ronit1710
August 31
@kevin.reliancegmail
https://discuss.codecademy.com/users/kevin.reliancegmail this was not
because oxnard was the only name in the javascript written by codecademy
but is due to the "this" pointer. When it says this.name it says the name
currently defined by the instance of the object. To make things simpler i
will say this pointer is used to point to th…

Visit Topic


or reply to this email to respond.

To unsubscribe from these emails, click here
https://discuss.codecademy.com/email/unsubscribe/4e782f620bd15b625f5bed5542cf85ffc829b0a134f31e3364cec6bf6dbdca31
.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.