Skip to content

Instantly share code, notes, and snippets.

@torifat
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torifat/9249906 to your computer and use it in GitHub Desktop.
Save torifat/9249906 to your computer and use it in GitHub Desktop.
Functional Mixin
var withWalking = function() {
this.walk = function() {
console.log(this.name + ' is walking');
};
this.turn = function(direction) { console.log('turning', direction);
};
this.stopWalking = function() {
console.log('stopped walking');
};
};
function Crocodile(name, gender) {
this.name = name;
this.gender = gender;
}
Crocodile.prototype.stalkTourists = function() {
//..
};
withWalking.call(Crocodile.prototype);
// ---
var croc = new Crocodile('Rifat');
croc.walk();
var withWalkingMehdi = function() {
this.walk = function() {
console.log(this.name + ' is running');
};
};
var croc2 = new Crocodile('Mehdi');
withWalkingMehdi.call(croc2);
croc2.walk();
var croc3 = new Crocodile('Nazmun');
croc3.walk();
@aburaihanrana
Copy link

nice work done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment