Created
July 2, 2015 01:25
-
-
Save shuding/7c87721ec3c0a04e5441 to your computer and use it in GitHub Desktop.
Aimless testing
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
| var add = function (x) { | |
| var self = this; | |
| self.value = x; | |
| var fn = function (x) { | |
| self.value += x; | |
| return fn; | |
| }; | |
| fn.valueOf = function () { | |
| return self.value; | |
| }; | |
| setTimeout(function () { | |
| fn = null; | |
| }, 5000); | |
| return fn; | |
| }; | |
| var x = add(2)(3); | |
| console.log(x); | |
| setTimeout(function () { | |
| console.log(x); | |
| }, 6000); | |
| // ===================== | |
| var f = function () { | |
| var ob = function () { | |
| return 1; | |
| }; | |
| setTimeout(function () { | |
| ob = function () { | |
| return 2; | |
| }; | |
| }, 1000); | |
| return ob; | |
| }; | |
| var s = f(); | |
| console.log(s()); | |
| setTimeout(function () { | |
| console.log(s()); | |
| }, 3000); | |
| // ===================== | |
| var h = function (x) { | |
| var self = this; | |
| self.value = 0; | |
| self.count = 0; | |
| function hn (x) { | |
| self.value += x; | |
| self.count ++; | |
| var stamp = self.count; | |
| setTimeout(function () { | |
| if (stamp == self.count) { | |
| console.log('Result = ' + self.value); | |
| hn = {}; | |
| } | |
| }, 0); | |
| return hn; | |
| } | |
| hn.valueOf = function () { | |
| return self.value; | |
| }; | |
| return hn.call(this, x); | |
| }; | |
| var t = h(3)(4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment