Created
September 8, 2013 05:57
-
-
Save mnvx/6482236 to your computer and use it in GitHub Desktop.
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 object = { | |
prop: 'object property', | |
method: function() { | |
console.log(this.prop); | |
} | |
} | |
// Так работает без ошибок | |
console.log("1:"); | |
object.method(); | |
// Так тоже работает! | |
console.log("2:"); | |
window['object']['method'](); | |
// А при таком вызове будет this.prop будет undefined, т.к. в качестве this в object сидит window | |
// TODO: как вызывать метод func, чтобы в обработчик в качестве this | |
// передавался не window, а объект? | |
console.log("3:"); | |
var func = window['object']['method']; | |
func(); | |
// Так тоже не работает | |
console.log("4:"); | |
var func = window['object']; | |
func['method'](); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment