« first day (4401 days earlier)      last day (769 days later) » 

05:41
@user31782 Depends on what the function that accepts callbacks does with the callback. If the function is synchronous then it cannot work any other way. Consider this code - it will run in the current event loop phase because the event loop will run until all the code present finishes executing. It's called "run to completion" cycle.
||> function f() {
	console.log("f");
}

function g() {
	console.log("g");
}

g();
f();
@VLAZ undefined Logged: [ '"g"', '"f"' ] Took: 0ms
Now if we modify it to make g() take a callback, we don't change anything that would matter to the run to completion semantics:
||> function g(callback) {
	console.log("g")
	callback();
}

function f() {
	console.log("f");
}

g(f);
@VLAZ undefined Logged: [ '"g"', '"f"' ] Took: 0ms
3 messages moved to Trash can
It's also the same as:
||> function f() {
	console.log("f");
}

function g() {
	f();
	console.log("g");
}

g();
@VLAZ undefined Logged: [ '"f"', '"g"' ] Took: 1ms
05:44
1 message moved to Trash can
(hmm, moving messages is useful when you make mistakes in the code)
At any rate, all three pieces of code do not have anything that would prevent them running to completion. Code is executed top to bottom with each call also completing before the execution continues. So, synchronous function that takes a callback and calls it will behave the same.
However, the function could be asynchronous, in which case it takes a callback because it cannot provide the result now, hence it needs some way to provide the caller with handling the result. Consider $.get(url, displayResultAsTable) which will make an AJAX call and then on completion pass the result to the displayResultAsTable function. In that case, the callback cannot be executed as part of the same event loop.
So, that's different to something like arrayofResults.forEach(displayResultAsTable) which does run synchronously.
 
1 hour later…
06:51
@VLAZ Thanks mate, I'd say in case ajax or even fetch(it's a promise so depending upon if the result is cached it might run in same event loop or if fetch was already complete) there would be countless event loops already run till the resource is downloaded.
No, an async function will always resolve something at least next event loop. There is no sane API that will sometimes be async and sometimes be synchronous.
 
2 hours later…
08:58
hello i have a knockoutjs question if you can help please do. thanks stackoverflow.com/questions/74291554/…
09:28
@Loyalty_Thameem Please don't post unformatted code - use the up arrow to edit your post, then hit Ctrl + K to format the code in that post. See the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
1 message moved to Trash can
How to access age value from the array of object in javascript?

const data = [{
"hello":'thameem',
"age":24
},
             {
"hello":'thameem',
"age":25
}];
console.log(data);

I need all age values
@Loyalty_Thameem data.map(x => x.age)
1695
Q: From an array of objects, extract value of a property as array

hydeI have JavaScript object array with the following structure: objArray = [ { foo: 1, bar: 2}, { foo: 3, bar: 4}, { foo: 5, bar: 6} ]; I want to extract a field from each object, and get an array containing the values, for example field foo would give array [ 1, 3, 5 ]. I can do this with this ...

@VLAZ It's working fine. The answer is (2) [24, 25]. But I need without array. like 24, 25. How can I do this?
You can't. You can only have one value per value. Not two. An array is one value but can contain multiple things. If you need to do something with each value, then loop over them.
:55468594 Okay. mr.Hero
 
1 hour later…
11:01
@VLAZ collections is something plenty of developers have troubles to grasp on, somehow
My boss is currently taking some programming courses for test automation (he's usually a manual tester) and is blown away by the concept of arrays. He even asked me if arrays are used often. And honestly, my answer was "no" (well, because he wasn't asking for JS) but mostly because other data structures are more common: lists, maps, sets.
In JS an array is essentially a list, so not sure how much I'd say JS uses "arrays" as a concept. Mostly as a name for something that's not a classical array.
I often ask other developer to explain me a difference between array and list, to see them struggling ;d
it's basically one difference. But the thing is that the answer varies on the language you're working on. As you've pointed out, "array" in js is basically a "list"
We there is a classical list in compsci theory. So there is something concrete you can point to, even if the implementations differ. Linked list will obviously not be the same as other types of lists. Even a double-linked list. The essential characteristics are: ordered collection of items, can be resized. While an array cannot be resized and it's a static structure.
11:25
@VLAZ I'd be more inclined to call ECMA arrays dictionaries (except for typed arrays, ofc)
Meh, only because you can attach random properties on them. But they are designed to work with sequential(-ish) data. Sparse arrays slightly deviate from the sequential part but are still there in spirit.
Maps rarely allow you to go through the contents and do stuff. Like filter or check if something fulfils a criterial. Get a "sub-map" the way you get a sub-list, as well.
Also maps/dictionaries are in an awkward place in terms of other collections, since all other collections are, to use TS terms, something like List<T>. While a map is Map<K, V>. Maps are always bound to two types of data items, other collections only operate with one. Even if you have something like List<[K, V]> - a collection of tuples is still "one thing".
11:44
@VLAZ well, ECMA these days guarantees the order of insertion in "dictionaries"
to be continued, I accidentally hit "enter" :)
..., and integer indexes are string-valued properties (canonical numeric strings), so array exotic objects are, IMO, only superficially different from objects [dicts] in terms of implementation.
> While an array cannot be resized and it's a static structure.
dis basically
yeah, and that - frankly, I still think it was a mistake to call ECMA Arrays "arrays" - it's hella confusing for anyone coming from a background different than JS
Yeah, I have to admit I had to adapt on it being "unlimited"
static arrays are rare though, not much use cases, but when you have it ... IIRC I created a module class FixedArray for this
@OlegValteriswithUkraine Could have just been called a list. That's what Python calls its thing which is denoted with square brackets, right?
11:59
@KarelG and for me, it was the other way around, given that I learned about CS terms way after I started programming. Yea, "proper" arrays don't have many use cases, but I'd rather have them than to have the overhead of arrays being special objects every time I need a fixed collection of numbers
Vaguely on the topic of arrays: Ugh, is there no decent duplicate for people wanting to filter + transform arrays? Often we get questions that use code like:
arr.filter(item =>  {
  if(item.isFoo)
    return item.bar;
}
Which obviously doesn't do both filtering and transformation.
@VLAZ yeah, that would be a better name, can't deny that - anything's better than "Array exotic objects"
@VLAZ dunno if we shouldn't simply close them to 2 dupe targets "how does filter work" and "how does map work", IMO
I may be a bit jaded, but not sure that someone who does not know what a predicate does can be helped by such a canonical
I struggle to find a duplicate that at least shows all of the common approaches. Of which there are few: 1. arr.filter().map() 2. arr.reduce() which will do both the filter and map (and can moves towards transducers) 3. a simple loop. 4.(-ish) libraries like Lodash with lazy iteration.
It's essentially three solutions, though. 4. is consequence of 2. and transducing the operations. But libraries that solve the problem can also be OK answers.
There is also iterators but it's not a radically different approach. I guess just a different way to do lazy evaluation.
@VLAZ transducers - is this... object-oriented function composition? Jeez
OK, turns out I have bookmarked saved something about it: How to filter and map array of objects in JavaScript?
12:08
@VLAZ well, that ain't a horrible one
I might drop in an answer or two to cover what isn't. At first glance, nobody mentioned bog standard loops.
I know it's not "kewl" but...it's simple, at least.
284
Q: Map and filter an array at the same time

Daniel Calderon MoriI have an array of objects that I want to iterate over to produce a new filtered array. But also, I need to filter out some of the objects from the new array depending of a parameter. I'm trying this: function renderOptions(options) { return options.map(function (option) { if (!optio...

how 'bout this one?
has filter + map, reduce, and even a flatMap solutions
Seems better, yes.
@VLAZ well, simply looping with for...of or similar is, indeed, indispensable when the values are promises, and they have to be resolved sequentially
@OlegValteriswithUkraine It's FP. Given that some of my favourite users who produce FP content on SO have written about it. There is Mulan there (who is just amazing) and also Scott Sauyet here. Scott is a creator of Ramda which is an FP toolkit and also Ramda does have transduce + looking at the tests of the library, it ensures a lot of the functions it exposes are valid transducers.
The transducer presented in the answer above is still just an FP construct. Uh, this is where my terminology fails me - I think it's technically an applicative functor but maybe the name is different. It's still a construct that builds up the effects, not unlike functor or monad.
12:19
@VLAZ yeah, I know - I was referring to the question specifically :) a builder pattern + FP feels a bit odd (not that I am npt guilty of making similar constructs myself, I have to admit)
12:53
IIRC there's a request for a .pipe thing for arrays somewhere in tc-39
13:13
forgot to add ...
if the arrays are handled in high level context (meaning each function does not return a new array), then this won't be an issue at all.
eg the aforementioned Python platform facilitates this
Also been on my "feature request" thing when talking about something js could use. What we now as features are bleh, marginal gains
13:27
  const cardRef = useRef<HTMLLIElement>(null)

  const cardHeight = cardRef.current !== null && +cardRef.current.offsetHeight


  const showOne = cardHeight;
  const showOneAndHalf = cardHeight + 1;
Operator '+' cannot be applied to types 'number | boolean' and 'number'.
Of course
because I have condition in front of number
how to fix that ?
const cardHeight = cardRef.current !== null && +cardRef.current.offsetHeight // be a bool
const showOneAndHalf = cardHeight + 1; // doing "bool + 1"
can you stop with torturing JavaScript, please?
1. fix the assignment. What is the purpose? The name cardHeight clearly indicates it should be a number. Treat it so
2. other problem gets solved but the variable name is odd showOneAndHalf appears to be a boolean but you want to do a "height of something plus one" on it.
hint: use optional chaining. (look it up)
 
1 hour later…
14:51
hello, does anyone use visual studio for JS? Is there a way to get more of it? I get no checks, no suggestions, nothing..
15:27
I use ST3
But yeah, I know most functions by heart. There are plugins you can use, eslint eg
i use vscode, it similarly provides nothing... when you haven't installed something that will provide something
AFAIK they have documented it
works quite well with typescript and flutter
yup - found it after some googling -> code.visualstudio.com/docs/languages/javascript
@KevinB probably not a surprise; ST3 has some troubles with TS type checks (false negatives). I even had to macro a ts compile to ensure that it's done correctly
anyways, I'm off for weekend
o/
VH SMP S3 launches this weekend
16:17
Is there a way for Javascript to know when the browser is being closed rather than refreshed?
@KevinB I don't know what those letters and numbers denote. Is it a thing? Several things?
@Hypersapien No.
 
2 hours later…
18:05
How the F can you trace how an event was triggered? I'm debugging it and I have a breakpoint in the event handler. But I don't know how the event is dispatched initially. Somehow pressing "enter" in a text field (in a form) sends a click event to a button element. The button isn't focused. The two are in the same form but I wouldn't have thought that Enter would trigger the button.
posted on November 03, 2022 by Ben Mason

Hi everyone! We've just released Chrome Dev 109 (109.0.5394.4) for Android. It's now available on Google Play. You can see a partial list of the changes in the Git log. For details on new features, check out the Chromium blog, and for details on web platform updates, check here. If you find a new issue, please let us know by filing a bug. Krishna Govind Google Chrome

@VLAZ Is it a submit button, or unrelated? Your enter keystroke might be bubbling up to the form
@Navigatron It's a <button> with no type. I know that such a button would submit the form (make it <button type="button"> so it doesn't) but I am not aware of the opposite happening - submitting the form also triggering the button.
And hitting Enter in the text box does submit the form. Hmm, maybe I should just try to emulate it with a simpler form to see how it works.
OMFG, it actually is that. Submitting the form triggers the first button it finds. Demo. Click in the text field and hit enter.
18:30
Hello @any, new here, can I ask question on mongoose nodejs?
@JoshM Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
@VLAZ VH -> Vault Hunters, minecraft modpack by Iskall85 - SMP -> Survival Multiplayer - S3 -> Season 3
@JoshM Fire away :)
Yea, thanks
So, i could update a user,
@VLAZ Wow, that's hilarious. I'll add that to my cache of oddities :D
18:39
!!mdn button
> If your buttons are not for submitting form data to a server, be sure to set their type attribute to button. Otherwise they will try to submit form data and to load the (nonexistent) response, possibly destroying the current state of the document.
!!mdn text input
@KevinB forward that to SE
They have few pieces of code that try to determine whether a button should submit or not. Like, one of them was for everything with a class that I forget the name of but it was something like "button-do-not-submit" or similar. And for those, it called e.preventDefault().
i'd love to instead point them at a question/answer on SO
18:52
@JoshM Please don't post unformatted code - use the up arrow to edit your post, then hit Ctrl + K to format the code in that post. See the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
1 message moved to Trash can
19:03
Sorry, was not aware of the formatting issue. Sample code link here: hastebin.com/acumacogaw.csharp
Please what am i doing wrong? It's been 2days trying to debug this. Could update user, could console.log posts by the old user, but I wanted to update users posts to the newly updated name, so that previous posts can display "by ${newname}". Thanks in advance.
19:58
posted on November 03, 2022 by Ben Mason

Hi everyone! We've just released Chrome Beta 108 (108.0.5359.30) for iOS; it'll become available on App Store in the next few days. You can see a partial list of the changes in the Git log. If you find a new issue, please let us know by filing a bug. Harry Souders Google Chrome

 
1 hour later…
21:18
export const LoginScreen = ({ error }: { error: ExpiredRefreshTokenError }) => {
  const { data: currentUser } = useAnonymousUser()
  const initialState =
    currentUser?.status === 'authenticating' ||
    currentUser?.status === 'authenticated'
  const [showValidateForm, setShowValidateForm] = useState(initialState)

  useEffect(() => {
    const updatedState =
      currentUser?.status === 'authenticating' ||
      currentUser?.status === 'authenticated'
    setShowValidateForm(updatedState)
probably because of this I am getting an error message
Error: Abort fetching component for route: "/dashboard"
I am using debugger and I see that component where I have router.push it's rendered twice
export const useAnonymousUser = () => {
  const router = useRouter()
  const result = useCurrentUser()
  if (result?.data?.status === 'authenticated') {
    router.replace('/dashboard')
  }
  return result
}
 
3 hours later…
23:52
posted on November 03, 2022 by Prudhvikumar Bommana

The dev channel has been updated to 109.0.5396.2 for Windows, Linux and Mac coming soon. A partial list of changes is available in the log. Interested in switching release channels? Find out how. If you find a new issue, please let us know by filing a bug. The community help forum is also a great place to reach out for help or learn about common issues. Prudhvikumar Bommana Google Chrome


« first day (4401 days earlier)      last day (769 days later) »