Skip to content

Author: admin@master

JavaScript Promises – reject vs. throw

I have read several articles on this subject, but it is still not clear to me if there is a difference between Promise.reject vs. throwing an error. For example, Using Promise.reject Using throw My preference is to use throw simply because it is shorter, but was wondering if there is any advantage of one over…

MomentJS set timezone without changing time

I’m trying to set the timezone for a date in moment.js without changing the time value I get a date in utc: and I need to set the time zone without changing the time. if I use date.utcOffset(moment().utcOffset()) it adds the offset: I could do but that seems like an inefficient way to do it. Is there an…

Pinch/pucker an image in canvas

How can I pinch/pucker some area of an image in canvas? I’ve made a solar system animation some time ago, and I started rewriting it. Now, I want to add gravity effect to masses. To make the effect visible, I turned the background into a grid and I’ll be modifying it. Desired effect is something l…

+ operator vs parseFloat

Example 1 of the knockout extenders page describes a way of rounding user input and making sure it is only numeric. It works great, but looking through the source they do a peculiar thing that i don’t understand, that is on line 8 they do this: newValue is a string. When i initially asked this question …

Can you bind ‘this’ in an arrow function?

I’ve been experimenting with ES6 for a while now, and I’ve just come to a slight problem. I really like using arrow functions, and whenever I can, I use them. However, it would appear that you can’t bind them! Here is the function: Here is the object I want to bind the function to: And here …