[Solved] What does mean '_' in this JavaScript code

Recommended Posts


Please, help me to understand what does mean '_' in this JavaScript code. I took this pease of code from here


    function createPoints(spawnBehavior)
        var ret = new THREE.Geometry();
        _.times(mode.particleCount, function (index)
        return ret;


Share this post

Link to post
Share on other sites

Thank you!

I found all libs from this example:

<script src='https://cdnjs.cloudflare.com/ajax/libs/three.js/r77/three.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js'></script>
<script src='http://cdn.rawgit.com/antishow/animation-controller/master/animation-controller.js'></script>
<script src='https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/controls/OrbitControls.js'></script> 
    <script src="js/three.min.js"></script>
    <script src="js/underscore-min.js"></script>
    <script src="js/animation-controller.js"></script>
    <script src="js/controls/OrbitControls2.js"></script>
    <script src="js/lodash.min.js"></script>



Share this post

Link to post
Share on other sites

It could actually be anything, JS variable assignment being what it is. _ just references an object, by convention, this has been 'claimed' by underscore, and then lodash, but also used by some functional libraries too (in the same way jQuery has claimed $), there's no formal claiming here, they just assign their libraries to this identifier, if you included two libraries that try to assign to the same identifier (such as underscore and lodash, not that you'd ever want to) then they'll clash and only one will get the reference.

As you've dug through the includes and found lodash, its pretty safe to assume that it refers to that library.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.