Проэлектроника

Мой блог

Пишу, что хочу ...

  • Home
    Home This is where you can find all the blog posts throughout the site.
  • Categories
    Categories Displays a list of categories from this blog.
  • Tags
    Tags Displays a list of tags that has been used in the blog.
  • Bloggers
    Bloggers Search for your favorite blogger from this site.
  • Team Blogs
    Team Blogs Find your favorite team blogs here.
  • Login

Поиграться со знаниями this

Posted by on in JavaScript
  • Font size: Larger Smaller
  • Hits: 3810
  • 0 Comments
  • Subscribe to this entry
  • Print
'use strict';

var test = {
    aa : function () {
        var bb = {
            j : function () {
                console.log(this);
            }
        };
        
        function bar () {
            return bb.j;
        }
        
        return bar()();
    }
};

test.aa(); // this === ???

Такой вариант:

'use strict';

var test = {
    aa : function () {
        var bb = {
            j : function () {
                console.log(this);
            }
        };
        
        function bar () {
            return bb.j();
        }
        
        return bar();
    }
};

test.aa(); // this === ???

И последний

'use strict';

var test = {
    aa : function () {
        var bb = {
            j : function () {
                console.log(this);
            }
        };
        
        function bar () {
            return bb.j;
        }
        
        return bar();
    }
};

test.aa()(); // this === ???
Tagged in: javascript scope this

Comments

  • No comments made yet. Be the first to submit a comment

Leave your comment

Guest Среда, 22 Ноябрь 2017
Joomla 2.5