Last active
August 29, 2015 13:56
-
-
Save torifat/9249906 to your computer and use it in GitHub Desktop.
Functional Mixin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice work done.