A general chat about JavaScript. Ask anything you like or share your best cat picture. Please check Google/StackOverflow for answers before asking for help. And remember, be nice! Don't ask to ask, just ask
@SeifESlimene Not every function that returns another function is a curried function, though. Suppose you call a "normal" (i.e., non-curried) function that takes three arguments.
foo(a, b, c)
If foo
was curried, you'd be calling it like this intead:
foo(a)(b)(c)
So basically, every curried function takes only one argument at a time. As long as you haven't provided all the arguments that are required, you just get another function that takes one argument. So foo
is a function that takes one argument, foo(a)
is a function that takes one argument, foo(a)(b)
is a function that takes one argument, and finally foo(a)(b)(c)
is the same value that the uncurried foo(a, b, c)
would return.
Now, the use case mostly comes in with partial application. Suppose I already know which a
and b
I want to pass to foo
, but I want to leave the choice of a c
to some other function bar
. Naievely, in the uncurried case, I might just pass a
and b
as additional arguments to bar
and have it make the final call to foo
:
-- definition of bar
function bar(a, b)
return foo(a, b, c)
end bar
-- later, calling bar
bar(a, b)
However, that requires that bar
already knows that I want to call foo
. What if bar
is a more generic function, which just expects any single-argument function and then passes c
to it? How do I ensure that it will invoke foo
with a
and b
already passed? In the uncurried case, I can write a wrapper function for this purpose:
-- definition of bar
function bar(func)
return func(c)
end bar
-- wrapping foo
function wrapFoo(a, b)
return function(c)
foo(a, b, c)
end
end wrapFoo
-- finally, calling bar
bar(wrapFoo(a, b))
Libraries for uncurried programming languages often provide a helper function so you don't have to write wrapFoo
yourself. For example _.partial
in Underscore for JavaScript. With such a helper function, we can do the same as above in less code:
-- definition of bar
function bar(func)
return func(c)
end bar
-- calling bar
bar(partial(foo, a, b))
In curried programming languages, however, you don't even need a helper function like partial
:
-- definition of bar
function bar(func)
return func(c)
end bar
-- calling bar
bar(foo(a)(b))
I hope the added value of currying is clearer this way. Let me know if you still have questions.
As a final remark, while some programming languages are curried by default and others are not, you can have both flavors in either type of programming language. In uncurried languages, you can write a curry
helper function that turns any function taking multiple arguments into a function that takes one argument at a time. In curried languages, you can write a function that accepts a tuple of values in order to simulate an uncurried function.
var filteredList = watchList.map(el =>
({
title: el['Title'],
rating: el['imdbRating']
})
).filter(movie => movie.rating >= 8.0);
```js
// your code here
```
getOwnPropertyNames
gets you all own properties while keys
gets you only the enumerable ones. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties for more details.
$.get
will call the error handler while fetch
only considers requests failed if no response comes back at all or if the response seems corrupt). fetch
is not as widely supported as $.get
(this can be addressed with a polyfill, but in that case you're probably not saving much space compared to just using jQuery). So definitely not exactly a drop-in replacement, but yes, they do serve the same purpose.
fetch
everywhere, I agree it doesn't make much sense to keep jQuery around just for $.get
.
pushTypeaheadSearchFormatField(element: any, index: any) {
this.formFields.push({
'key': element[index].name,
'wrappers': ['labelWrapper'],
'type': 'typeahead',
'defaultValue': element[index].defaultValue,
'templateOptions': {
'type': 'typeahead',
'key': element[index].name,
'label': element[index].displayName,
'required': element[index].isRequired && element[index].isRegulatoryRequirement ? false : element[index].isRequired,
'isRegulatoryRequirement': element[index].isRegulatoryRequirement,
'dependencyRules': element[index].dependencyRules,
'showLookupNotice': element[index].isOptionRequired,
'optionsUrl': element[index].optionsUrl,
'changeExpr': 'this.getData($event, field)',
'isregularatoryProduct': this.isregularatoryProducts(element[index].name),
'placeholder': 'Typeahead States',
'search$': (term) => {
if (term && term.length > 2) {
this._http.get<any>(AppConstants.wkApiUrl.producerCode).subscribe(result => {
const product = result.paginationData.map(key => key['name']);
const filteredProduct = product.filter(v => v.toLowerCase().indexOf(term.toLowerCase()) > -1).slice(0, 10);
return of(filteredProduct);
})
} else {
return of([]);
}
// const states = this.states.map(key => key['name']);
// if ((!term || term === '')) {
// return of(states);
// }
// return of(states.filter(v => v.toLowerCase().indexOf(term.toLowerCase()) > -1));
},
},
});
}
filterData(result, term) {
const product = result.paginationData.map(key => key['name']);
const filteredProduct = product.filter(v => v.toLowerCase().indexOf(term.toLowerCase()) > -1).slice(0, 10);
return of(filteredProduct);
}
anyone help me about javascript with styling . here is my code snippet
i want when complete the bar percentage from the html means it get the percentage from an html and apply it using js dynamically
ok, if you check the code snippet UI that have a percentage bar which is completed bar in percentage based on percentage written in html or above in every line. So as of now that is working fine with css. But i am trying to achieve that using javascript .
and remove css when it's coming from javascript
.skills__html {
width: 60%;
}
.skills__css {
width: 70%;
}
.skills__js {
width: 75%;
}
.skills__react {
width: 90%;
}
@jgonggrijp
:point_up: Edit: Hi, having a bit of a conundrum.
Material-UI/pickers.datepicker has been deprecated (mui-org/material-ui-pickers#2157), and I'm currently at work with a task to do some style changes to and existing picker based on this datepicker. But the style changes would require me to migrate to the new version for a specific override feature (for popover dynamic styling based on props).
Now the question is, should I migrate to @mui/lab and mui v5 in the future, or just avoid mui altogheter and include a vanilla js datepicker (https://github.com/qodesmith/datepicker) to customize. I have to rewrite the component regardless.
What are your toughts on MUI in general? Is it worth the hassle when we have to customize with company styles anyway? I've been on the fence for a while, but am considering to drop it altoghether
Edit: concluded with fuck MUI
:point_up: Edit: Hi, having a bit of a conundrum.
Material-UI/pickers.datepicker has been deprecated (mui-org/material-ui-pickers#2157), and I'm currently at work with a task to do some style changes to and existing picker based on this datepicker. But the style changes would require me to migrate to the new version for a specific override feature (for popover dynamic styling based on props).
Now the question is, should I migrate to @mui/lab and mui v5 in the future, or just avoid mui altogheter and include a vanilla js datepicker (https://github.com/qodesmith/datepicker) to customize. I have to rewrite the component regardless.
What are your toughts on MUI in general? Is it worth the hassle when we have to customize with company styles anyway? I've been on the fence for a while, but am considering to drop it altoghether
Edit: concluded with fuck MUI
Edit 2: when with this one if anyone cares; https://github.com/wwilsman/Datepicker.js
:point_up: Edit: Hi, having a bit of a conundrum.
Material-UI/pickers.datepicker has been deprecated (mui-org/material-ui-pickers#2157), and I'm currently at work with a task to do some style changes to and existing picker based on this datepicker. But the style changes would require me to migrate to the new version for a specific override feature (for popover dynamic styling based on props).
Now the question is, should I migrate to @mui/lab and mui v5 in the future, or just avoid mui altogheter and include a vanilla js datepicker (https://github.com/qodesmith/datepicker) to customize. I have to rewrite the component regardless.
What are your toughts on MUI in general? Is it worth the hassle when we have to customize with company styles anyway? I've been on the fence for a while, but am considering to drop it altoghether
Edit: concluded with fuck MUI
Edit 2: wentwith this one if anyone cares; https://github.com/wwilsman/Datepicker.js
extend(DiscussionHero.prototype, 'oninit', function () {
const GameApi = fetch('https://api.rawg.io/api/games/call-of-duty-modern-warfare?page_size=1&page=1&key=myapi')
.then(response => response.json())
.then(data => {
this.gameDet = data;
console.log(data)
console.log(this.gameDet.name)
console.log(this.gameDet.description_raw)
console.log(this.gameDet.metacritic)
})
})
extend(DiscussionHero.prototype, 'items', function (items) {
items.add(
'aaaa',
<div className="myclass">
<div class="myclass">
// <------------------------------------------------ I WANT TO DISPLAY this.gameDet.name HERE
</div>
</div>
);
});
knexClient.schema.createTable("events", (table) => {
table.increments();
table.dateTime("starts_at").notNullable();
table.dateTime("ends_at").notNullable();
table.enum("kind", ["appointment", "opening"]).notNullable();
table.boolean("weekly_recurring");
});