Prototype to the Rescue


#1


https://www.codecademy.com/en/courses/objects-ii/2/4?curriculum_id=506324b3a7dffd00020bf661


Nothing wrong, I'm just curious what is the difference of buddy.bark() vs buddy.bark //without the parenthesis?
Why does it print with the parenthesis but not without, but it still lets me pass the exercise?



function Dog (breed) {
  this.breed = breed;
}

// here we make buddy and teach him how to bark
var buddy = new Dog("golden Retriever");
Dog.prototype.bark = function() {
  console.log("Woof");
};
buddy.bark();

// here we make snoopy
var snoopy = new Dog("Beagle");
/// this time it works!
snoopy.bark();


#2

buddy.bark is an expression. buddy.bark() is a statement. Nothing happens in the former. The parens are what invokes the method.


#3

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