Help understand widget.js twitters file, closing in closing?

http://a2.twimg.com/a/1302724321/javascripts/widgets/widget.js?1302801865

It is configured at a high level:

public namespace:

TWTR = window.TWTR || {};

Then the closure:

(function() {
...

})(); // #end application closure

Within application closure:

TWTR.Widget = function(opts) {
    this.init(opts);
};
(function() {
    // Internal Namespace.
    var twttr = {};
})();

Some methods are marked as public, others are private, and the only difference seems to be the naming convention (private begins with the underscore '_').

Is it designed using a module template?

Why or what is the use of closing in closing?

Since they load widget.js before jquery, does that mean the widget is designed to run without jquery, since the order matters?

Just trying to learn this!

+5
1

:

:

TWTR = window.TWTR || {};

, var. javascript " ", , . , .

:

> (function() { ...
> 
> })(); // #end application closure

iife. , , . , - . , , - , (, gobbledy-goop). iif, .

create, .

:

> TWTR.Widget = function(opts) {
>     this.init(opts); }; (function() {
>     // Internal Namespace.
>     var twttr = {}; })();

, , ( '_').

"public" "private" javascript. , "" . , API, , API, .

.

?

" " - . "private" javascript, , . widget.js ( ) , , , .; -)

?

, . , [[]], ( ) - , [[]].

Edit

, , , , , , , , , . , , , , , (, , ).

.

var foo = (function() {

  // Variables available for closure
  var a, b, c;

  // Use a, b, c for stuff
  ...

  // Only want closure to c
  a = null;
  b = null;

  return function() {
    // use c
  }
}());

widget.js jquery, , jquery, ?

( twitter), , . , , , .

+4

All Articles