Posts

Showing posts with the label broken

Opera, Inevitably Unexpected

Update Opera fellas works at speed light, the problem described in this post has been patched already , great stuff and thanks! Just a quick one, about what I have discovered with Opera 10.62 when I have tested wru against this browser ... // host object var xhr = new XMLHttpRequest; // this is true alert("addEventListener" in xhr); // this is undefined // not even null // simply undefined!!! alert(xhr.addEventListener); The Problem 99% of libraries out there are assuming that key in object is one of the fastest and most reliable way to have features detection . Today, we know that this assumption is wrong . It's not about the reproducibility of the problem: var o = {}; o.key = o.key; "key" in o && o.key; It's about an ... Epic Fail (Already Fixed!) The engine " behind the scene " is broken . Whatever it happens there, we have a broken chain through pseudo inheritance that exposes publicly a method that does not exist , which brings u...

[Q&D] Fix Decimal Module Operator

This is a Q&D solution for some JavaScript precision problem when we use the module operator with floating point numbers. The Problem If we are dealing with the module operator we could have this case: alert( 8.25 % .05 ); // 0.049999999999999545 We expected 0 but we have a floating point inconsistency instead. This is a well known problem, and not only with JavaScript, truly annoying when we have to show run-time computed money/trends operations. The Solution This comes from my reply in a JS forum, knowing that the module will be a simply floating point, let's say .1 to .001, if we remove floating point from the right side of the operation everything works just fine: function mod(num, mod){ // Another WebReflection silly idea var pow = Math.pow(10, (("" + mod).split(".")[1] || "").length); return ((num * pow) % (mod * pow)) / pow; }; alert( mod(8.25, .05) ); // 0 alert( mod(8.25, .1) ); // 0.5 That's it, have a nice ...