mercredi 10 février 2016

How to create properties for a Strategy Design Pattern in javascript?

http://ift.tt/1T8t3NH

this part of the code from the link above is giving me trouble. background: running in a chrome extension under "use strict" conditions

var Greeter = function(strategy) {
  this.strategy = strategy;  
};

// Greeter provides a greet function that is going to
// greet people using the Strategy passed to the constructor.
Greeter.prototype.greet = function() {
  return this.strategy();
};

I think i need to Create the property 'greet' but don't know how to.

I keep getting error saying "cannot set property 'greet' of undefined"

How can I create the property greet and get the code to work?

Thanks!

Aucun commentaire:

Enregistrer un commentaire