Показать сообщение отдельно
  #2 (permalink)  
Старый 18.05.2013, 13:55
Аватар для Aetae
Тлен
Отправить личное сообщение для Aetae Посмотреть профиль Найти все сообщения от Aetae
 
Регистрация: 02.01.2010
Сообщений: 6,491

Javascript же:
(
    function(root, factory) {
 
        // Проверяет переменные, откуда эти переменные тут взялись?
         
        /* CommonJS */
        if (typeof exports == 'object')  module.exports = factory()
 
        /* AMD module */
        else if (typeof define == 'function' && define.amd) define(factory)
 
        /* Browser global */
        else root.Spinner = factory()
    }
     
     
    (this, function() {
         
        // Тут основной код
        // .......
         
        // Тут еще идет функция, которая вызывается
        /** The constructor */
        function Spinner(o) {
            if (typeof this == 'undefined') return new Spinner(o)
            this.opts = merge(o || {}, Spinner.defaults, defaults)
        }
    })
)
~
function temp(root, factory) {
 
        // Проверяет переменные, откуда эти переменные тут взялись?
         
        /* CommonJS */
        if (typeof exports == 'object')  module.exports = factory()
 
        /* AMD module */
        else if (typeof define == 'function' && define.amd) define(factory)
 
        /* Browser global */
        else root.Spinner = factory()
}
     
     
temp(this, function() {
         
        // Тут основной код
        // .......
         
        // Тут еще идет функция, которая вызывается
        /** The constructor */
        function Spinner(o) {
            if (typeof this == 'undefined') return new Spinner(o)
            this.opts = merge(o || {}, Spinner.defaults, defaults)
        }
})
~
function temp(root, factory) {
 
        // Проверяет переменные, откуда эти переменные тут взялись?
         
        /* CommonJS */
        if (typeof exports == 'object')  module.exports = factory()
 
        /* AMD module */
        else if (typeof define == 'function' && define.amd) define(factory)
 
        /* Browser global */
        else root.Spinner = factory()
}
     
var temp1 = this;
var temp2 =  function() {
         
        // Тут основной код
        // .......
         
        // Тут еще идет функция, которая вызывается
        /** The constructor */
        function Spinner(o) {
            if (typeof this == 'undefined') return new Spinner(o)
            this.opts = merge(o || {}, Spinner.defaults, defaults)
        }
}     

temp( temp1, temp2)


Если вызов происходит в глобальном контексте, то в обычном режиме this === window, в strict: this === undefined.
__________________
29375, 35
Ответить с цитированием