Last active
August 29, 2015 14:04
-
-
Save rnapier/478465d1b15e95b98b42 to your computer and use it in GitHub Desktop.
Spooky action at a distance when you don't use self
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
// Try this in a commandline app vs a playground. The behaviors are different. | |
class MyClass { | |
func doSomething() { | |
refresh() // I wonder which refresh we'll get? | |
} | |
} | |
// Not only does this change the behavior of doSomething()... (see below) | |
// extension MyClass { | |
// func refresh() { | |
// println("I'm an extension refresh") | |
// } | |
//} | |
func refresh() { | |
println("I'm the global refresh function.") | |
} | |
// ... but it behaves *differently* if it's here | |
//extension MyClass { | |
// func refresh() { | |
// println("I'm an extension refresh") | |
// } | |
//} | |
MyClass().doSomething() | |
// see also https://gist.github.com/rnapier/4213dc64206b17df6935 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment