Skip to content
Advertisement

Tag: ecmascript-6

Using await within a Promise

There seems something inherently wrong with having to define a Promise’s callback as asynchronous: This is apparently an antipattern and there are coding problems which can arise from it. I understand that it becomes easier to fail to catch errors here, even when placing await statements inside try/catch blocks. My first question is, what’s the best way to code something

Unable to display Date in JSX in ReactJS

Following is my code which is working fine if I initialize test with a string, though if I changed it to new Date() its throwing error. Let me know what I am doing wrong as I just started with React. Code – Error – Objects are not valid as a React child (found: Fri Jul 21 2017 02:11:18 GMT+0530 (India

How to properly use Object.setPrototypeOf()

So I’ve been getting up to speed on some of the newer features of JavaScript and have been reading about Object.setPrototypeOf(). I ran across this bit of code from MDN which deals with inheriting from regular objects. But I’m confused at how they use Object.setPrototypeOf() here. I expected them to write as opposed to what the do below. Why do

Programmatically cause onBlur to trigger in react

I use onBlur to close a dropdown, but I also want to handle a click handler of an li which is render within, setState won’t work here, the behavior is broken when user try to open the dropdown again, try it here: http://jsfiddle.net/ur1rbcrz My code: Answer Your code is not working because, even though you click li, a div container

Enums in Javascript with ES6

I’m rebuilding an old Java project in Javascript, and realized that there’s no good way to do enums in JS. The best I can come up with is: The const keeps Colors from being reassigned, and freezing it prevents mutating the keys and values. I’m using Symbols so that Colors.RED is not equal to 0, or anything else besides itself.

Advertisement