jquery - What this JavaScript function method called? -
i quite interested when run simple function
$(window).resize(function() { var = $(this); var widthvalue = that.width(); console.log(widthvalue + 'px'); });
it works when start resizing browser window.
but when this
$(window).resize(function() { var = $(this); var widthvalue = that.width(); console.log(widthvalue + 'px'); }).resize();
it acts load();
. added resize()
@ end.
what called? not sure understand why , how works.
the technique called chaining.
it boils down function returning this
@ end, can call method of same object chaining method calls 1 after other.
var foo = { count: 0, up: function () { this.count++; return this; }, show: function () { alert(this.count); return this; } } foo.show().up().show().up().up().show();
in particular example, resize
method overloaded. if give function argument bind function event handler. if call without arguments, trigger event instead.
Comments
Post a Comment