Created
August 8, 2015 05:46
-
-
Save chuck0523/9c6ef58650f6b8b14b1a to your computer and use it in GitHub Desktop.
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 myObj = { | |
value : 0, | |
increment : function(inc) { | |
this.value += typeof inc === 'number' ? inc : 1; | |
} | |
}; | |
myObj.increment(); | |
console.log(myObj.value); // 1 | |
myObj.increment(2); | |
console.log(myObj.value); // 3 | |
var add = function(a, b) { | |
return a + b; | |
} | |
myObj.double = function() { | |
var that = this; | |
var helper = function() { | |
that.value = add(that.value, that.value); | |
}; | |
// 関数呼び出し | |
helper(); | |
} | |
// メソッド呼び出し | |
myObj.double(); | |
console.log(myObj.value); // 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment