Code Monkey home page Code Monkey logo

Comments (4)

camerow avatar camerow commented on May 13, 2024 1

Craig stole my thunder. Get out of here Craig! (We work together...=D).

from just.

angus-c avatar angus-c commented on May 13, 2024

Actually this is a great question.
When you invoke partial you need to pass placeholder arguments for this arguments you want to supply at runtime. In the following example we want to return a function that resolves the cubed root of something. That something is the placeholder indicated by _

import partial from 'just-partial-it';

const cubedRoot = partial(Math.pow, _, 1/3);
cubedRoot(10).toFixed(1); // 56.7
cubedRoot(35).toFixed(1); // 16.2

We need a way for the caller of partial to pass in an argument that will be recognized as a placeholder. One way to do this is to use a global variable. This is where globalObj.___ comes in.

Your question reveals a shortcoming in my example. We should first assign _ to globalObj.___ before calling partial. (without this the function would likely throw an error since _ is probably undefined).

So for the example to work properly we need:

import partial from 'just-partial-it';

var _ = global.___;
const cubedRoot = partial(Math.pow, _, 1/3);
cubedRoot(10).toFixed(1); // 56.7
cubedRoot(35).toFixed(1); // 16.2

Which is annoying. I'm going to rewrite this to just use null as the placeholder which will mean we can remove all this global nonsense.

Thanks for bringing to my attention!

from just.

craigbeck avatar craigbeck commented on May 13, 2024

Actually using _ (which is undefined) results in NaN as result from examples. Pull request #8 uses undefined as placeholder. null could be valid and useful value to pass, but undefined is clear, explict, and unambigous (i.e. null is value or placeholder?)

from just.

angus-c avatar angus-c commented on May 13, 2024

@camerow feel free to find another bug :)

from just.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.