Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var obj = (function ($) {
- return {
- func1: function () {
- console.log("do something");
- },
- func2: function () {
- // do something
- $("#debug").click(function () {
- // do something
- func1();
- // do something
- })
- }
- }
- })(jQuery);
- obj.func2(); // по клику на #debug получаем - Uncaught ReferenceError: func1 is not defined
- var obj = (function ($) {
- return {
- func1: function() {
- console.log("do something");
- },
- func2: function () {
- $("#debug").click(function () {
- this.func1(); //2. обращаемся к нужному контексту
- }.bind(this)) //1. привязываем контекст
- }
- }
- })(jQuery);
- obj.func2();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement