8Observer8

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

Recommended Posts

Hello

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)
        {
            ret.vertices.push(spawnBehavior(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>

 

Snowstorm.zip

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.