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 Counter = 0; | |
> Counter.prototype.next = function() { | |
> this += 1; | |
> return this; | |
> }; |
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 count = Counter; | |
> count.next(); | |
1 | |
> var accidental_class_ref = Counter; | |
> accidental_class_ref.next(); | |
1 | |
> var another_counter = new Counter; | |
> another_counter.next(); | |
2 |
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 count = Counter; | |
> count; | |
0 | |
> count.next() | |
1 |
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 Counter = 0; | |
> Counter.next = function() { | |
> this += 1; | |
> return this; | |
> }; |
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 count = new Counter; | |
> count.next(); | |
Error: function next is not defined. |
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 Counter = function(from) { | |
> this.from = from; | |
> this.next = function() { | |
> this.from += 1; | |
> return this.from; | |
> }; | |
> } | |
> var count_from_7 = new Counter(7); | |
> var count_from_3 = new Counter(3); | |
> count_from_7.next(); |
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 base = change_this_one(10); | |
> one; | |
10 |
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 one = 1; | |
> var change_this_one = function(baseline) { | |
> this.one = baseline; | |
> } | |
> one; | |
1 | |
> var base = new change_this_one(10); | |
> one; | |
1 | |
> base.one; |
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 three = new next(2); | |
> three; | |
3 |
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 next = function(input) { | |
> return input + 1; | |
> } | |
> var three = new next; | |
> three; | |
[Function] | |
> three(2); | |
3 |