0

I am learning JavaScript and came to a point wherein I have to load underscore.js in the chrome console. I did some search and ended at this stackflow response: How to enable to use underscore in console in Chrome developer tool?

The code snippet provided in the above link works for me. But I could not figure out what does window.R object refer to? Why do I need to include this? Can't I just add the script element and load the underscorejs?

I am referring the below piece of code in the stackoverflow response provided. thanks!

(function () {
  if (typeof window.R === 'undefined') {    
    var s = document.createElement('script');
    s.type = 'text/javascript';
    s.src = 'https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js';
    document.head.appendChild(s);
    }
}());
jjj
  • 1,136
  • 3
  • 18
  • 28
srinu259
  • 309
  • 4
  • 14
  • 6
    Underscore does not appear to create any `window.R`. I think the answer's code is wrong - the check should be for `window._` instead. – CertainPerformance Aug 20 '18 at 07:58
  • 1
    agree we should check `window._` instead. you line #2 should be like `if ( window._ === undefined ) { ` – Deepak Sharma Aug 20 '18 at 08:37
  • 1
    Yes right, it's a typo and should be window._: means that if window object doesn't contain underscore variable, then add its related script to the head of your document. If anything still not clear please tell – hd84335 Aug 20 '18 at 17:58
  • thank you! for the responses! this is clear for me now – srinu259 Aug 21 '18 at 03:51

0 Answers0