Created
May 17, 2016 20:45
-
-
Save esova-ana/6514664630fc966dcee82a5435083bd6 to your computer and use it in GitHub Desktop.
Returning an object with functions (CodeCombat)
This file contains hidden or 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
function summonHero (name, position) { | |
return { | |
say: function (sentence) { | |
alert(sentence); | |
}, | |
move: function (position) { | |
console.log('Moving to x=' + position.x + ' and y=' +position.y); | |
this.pos = position; | |
}, | |
name: name, | |
pos: position | |
}; | |
} | |
var ana = summonHero('Ana', {x:0,y:0}); | |
console.log(ana.say('hello')); | |
console.log(ana.pos); | |
console.log(ana.move({x:10,y:10})); | |
console.log(ana.pos); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment