Last active
April 10, 2018 10:49
-
-
Save zhangkaizhao/6be058d9e3e1ccc69b068316943f4622 to your computer and use it in GitHub Desktop.
Python `__eq__` compared to JavaScript closure
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
// via Telegram Desktop CPyUG group fy | |
// https://stackoverflow.com/a/48298565/2837824 | |
const a = { | |
i: 1, | |
toString: function() { | |
return a.i++; | |
} | |
} | |
if (a == 1 && a == 2 && a == 3) { | |
console.log("Hello World!"); | |
} |
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
class Number: | |
def __init__(self, value=1): | |
self.value = value | |
def __str__(self): | |
return str(self.value) | |
def __eq__(self, another_value): | |
# print(self.value) | |
result = self.value == another_value | |
self.value = self.value + 1 | |
return result | |
a = Number() | |
if a == 1 and a == 2 and a == 3: | |
print("Hello World!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment