Comments (4)
Craig stole my thunder. Get out of here Craig! (We work together...=D).
from just.
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.
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.
@camerow feel free to find another bug :)
from just.
Related Issues (20)
- Bug: Not loading in NextJS production mode.
- [just-diff] keep the old value in the diff HOT 1
- [Feature] Diff apply only added/updated? HOT 2
- Permutations gives incorrect result for arrays of arrays
- just-safe-set docs do not agree with implementation HOT 2
- [BUG] After `diff(object, master);` - master changed
- [just-rotate-right] Rotate array elements to the right
- [just-omit] webpack import error HOT 3
- just-diff Error when first diff is a complex array mutation
- [just-diff] op type error.I add a new property with an empty string,but the op is replace HOT 1
- Website missing one-line descriptions for each library
- `just-is-empty` function fails to detect symbol properties in objects
- Proposal: `hasOnly` object utility
- safe-set sorting bug
- Types of just-diff and just-diff-apply do not match HOT 1
- `just-standard-deviation` and `just-skewness` require 2 numbers in the array HOT 1
- Could not find a declaration file for module `just-pipe` HOT 1
- flatten with depth=1 is not properly applied to the first element HOT 1
- function just-diff is buggy when dealing with empty objects with no prototype
- just-intersect is mixing array and strings HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from just.