Trying to use composition over inheritance with factory functions in Javscript and I am getting function is not defined with the following code:
(dogIsCreated is not defined)
var dog = function dog(state) {
return {
create: function create() {
console.log('Create the dog');
dogIsCreated();
},
dogIsCreated: function dogIsCreated() {
console.log('Ready');
}
}
}
var ted = dog().create();
Be amazing if someone could point me in the right direction? Am I using completely the wrong syntax.
Thanks :)
var dog = function dog(state).dogIsCreated(at least in the scope you are trying to call it from).dogIsCreatedis a property on the object. Maybe you meantthis.dogIsCreated()?thisis required?