2014-02-20 76 views
0

當我運行在Chrome DevTool這個代碼,防止require.js登錄自己安慰

require(['common'], function (common) { common.getProfilPic(123); }) 

它總是打印requirejs整個代碼塊,

function localRequire(deps, callback, errback) { 
        var id, map, requireMod; 

        if (options.enableBuildCallback && callback && isFunction(callback)) { 
         callback.__requireJsBuild = true; 
        } 

        if (typeof deps === 'string') { 
         if (isFunction(callback)) { 
          //Invalid call 
          return onError(makeError('requireargs', 'Invalid require call'), errback); 
         } 

         //If require|exports|module are requested, get the 
         //value for them from the special handlers. Caveat: 
         //this only works while module is being defined. 
         if (relMap && hasProp(handlers, deps)) { 
          return handlers[deps](registry[relMap.id]); 
         } 

         //Synchronous access to one module. If require.get is 
         //available (as in the Node adapter), prefer that. 
         if (req.get) { 
          return req.get(context, deps, relMap, localRequire); 
         } 

         //Normalize module name, if it contains . or .. 
         map = makeModuleMap(deps, relMap, false, true); 
         id = map.id; 

         if (!hasProp(defined, id)) { 
          return onError(makeError('notloaded', 'Module name "' + 
             id + 
             '" has not been loaded yet for context: ' + 
             contextName + 
             (relMap ? '' : '. Use require([])'))); 
         } 
         return defined[id]; 
        } 

        //Grab defines waiting in the global queue. 
        intakeDefines(); 

        //Mark all the dependencies as needing to be loaded. 
        context.nextTick(function() { 
         //Some defines could have been added since the 
         //require call, collect them. 
         intakeDefines(); 

         requireMod = getModule(makeModuleMap(null, relMap)); 

         //Store if map config should be applied to this require 
         //call for dependencies. 
         requireMod.skipMap = options.skipMap; 

         requireMod.init(deps, callback, errback, { 
          enabled: true 
         }); 

         checkLoaded(); 
        }); 

        return localRequire; 
       } require.js:1361 
require(['common'], function (common) { console.log(common.getProfilPic(123)); }) 
function localRequire(deps, callback, errback) { 
        var id, map, requireMod; 

        if (options.enableBuildCallback && callback && isFunction(callback)) { 
         callback.__requireJsBuild = true; 
        } 

        if (typeof deps === 'string') { 
         if (isFunction(callback)) { 
          //Invalid call 
          return onError(makeError('requireargs', 'Invalid require call'), errback); 
         } 

         //If require|exports|module are requested, get the 
         //value for them from the special handlers. Caveat: 
         //this only works while module is being defined. 
         if (relMap && hasProp(handlers, deps)) { 
          return handlers[deps](registry[relMap.id]); 
         } 

         //Synchronous access to one module. If require.get is 
         //available (as in the Node adapter), prefer that. 
         if (req.get) { 
          return req.get(context, deps, relMap, localRequire); 
         } 

         //Normalize module name, if it contains . or .. 
         map = makeModuleMap(deps, relMap, false, true); 
         id = map.id; 

         if (!hasProp(defined, id)) { 
          return onError(makeError('notloaded', 'Module name "' + 
             id + 
             '" has not been loaded yet for context: ' + 
             contextName + 
             (relMap ? '' : '. Use require([])'))); 
         } 
         return defined[id]; 
        } 

        //Grab defines waiting in the global queue. 
        intakeDefines(); 

        //Mark all the dependencies as needing to be loaded. 
        context.nextTick(function() { 
         //Some defines could have been added since the 
         //require call, collect them. 
         intakeDefines(); 

         requireMod = getModule(makeModuleMap(null, relMap)); 

         //Store if map config should be applied to this require 
         //call for dependencies. 
         requireMod.skipMap = options.skipMap; 

         requireMod.init(deps, callback, errback, { 
          enabled: true 
         }); 

         checkLoaded(); 
        }); 

        return localRequire; 
       } 

和和我看到日誌結果,並想法如何阻止requirejs打印自己?

回答

0

運行此相反:

(function(){ require(['common'], function (common) { common.getProfilPic(123); }) })() 
0

什麼情況是,控制檯打印出表達式的值。函數調用的值是調用返回的值。您可以輕鬆地解決它的東西,如:

require(['common'], function (common) { common.getProfilPic(123); }); 1 

添加; 1會使表達計算爲1。所以你會得到在控制檯上1但至少它不會推診斷信息在屏幕上。