You are right in saying that what many (if not most) people in the JavaScript community refer to as currying does not really correspond to the term as defined in Haskell.
Then again, neither does partial application. A partial application of all arguments is a full application, but this in not happening here, because if you do this for all arguments, you will still not have applied the function, but rather created a niladic function from it (a distinction that makes no sense in Haskell).
At the bottom line, for a JavaScript programmer it's more important to understand what other JavaScript programmers mean by "currying" or "partial application", than what a non-JavaScript programmer use the term for.
FIY, I think the correct (and not unheard of) term here is binding. You bind the arguments of a function. In particular, you can also bind the implicit this
argument of a function.
A high-level dissection of the code posted:
<script type="text/javascript">
Html-element to embed a script in it
$("#circle")
$ is the jQuery alias for getting the jQuery object which wraps almost all of the stuff jQuery can do. In this case we simply invoke the jQuery object with syntax similar to that of a constructor. This is shorthand for "pass in a css-selector and return all matched DOM elements wrapped as jQuery elements". So we select the element in the DOM with id=circle
.click(
This is (one of many) jQuery-ways to say when the element(s) - the previous selector could have returned a ton of elements - is clicked run the function passed into me. This function is called a callback-function. Basically subscribing to the onclick event of the DOM element.
function() {
.. the callback passed in...
$("p")
Similar to the $("#circle")-statement. Select all paragraph-elements in the DOM as jQuery elements. (<p></p>
)
.html("You clicked the circle");
For all p-elements previously selected set the inner html of this elements to be "You clicked the circle". Note; You should almost never want to do this for security reasons - use .text() instead.
}
.. close the call back ..
)
.. Honorably mention; You forgot to close the click()-function :) The code as-is will still work though, since javascript is forgiving (For better or for worse, that's another story)
</script>
.. closing the script-tag..
As it has been stated, this is a really broad question even though it does not look like it. For all the above paragraphs you could probably write a page of what it really does under the hood, but that's the gist of it.
For your question "Does jQuery convert the resulting code to JavaScript?". Not really. jQuery is implemented in javascript, so you can simply think of it as a wrapper library. jQuery serves two main purposes: 1) Providing an API that works regardless of browser types. So for example, if Safari has some quirks working with the onclick-event but firefox follows the spec, jQuery will take care of this under the hood for you (Not the the Safari/Firefox example is purely made up, none of those should have quirks). And 2) provide QoL-improvements such as CSS-selectors, although those have since been implemented in ES5 or ES6, can't remember which. When jQuery came out you had to call document.getElementById() or a similar DOM-method to select elements.
At the risk of starting a religious war, jQuery has nowadays largely served its purpose. Most of the stuff that made jQuery popular is now implemented in recent ECMAScript-versions and most browsers are now updated to at least include the basic stuff. Personally, I only use it because it's a familiar API, as I used to work extensively with it, but it's not "as required" to use it as it once was.
Hope it helps :)
Best Answer
Since it's not clear what part of this is confusing you, let's take this step by step.
1)
Boolean
is a function. In this case, it takes one argument, and returns either true or false depending on whether the argument was truthy or falsy. So if it helps, you could replaceBoolean
withfunction(x) { return !!x; }
and get roughly the same behavior.2) This line:
is interchangeable with:
Assuming the identifier
func
is not used anywhere else in your code.3)
noisy(Boolean)
obviously calls thenoisy
function, withf
set to the functionBoolean
. The call tonoisy
then returns a function like this:4) The function returned by
noisy
is then called with0
as the value ofarg
. That effectively does the following:5) If #1 made sense, then it shouldn't be surprising that
Boolean(0)
evaluates tofalse
. From there it should be obvious why the output is what it is.