snehalmasne / datejs

Automatically exported from code.google.com/p/datejs
Other
0 stars 0 forks source link

Extended Number.prototype #167

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Add <script src="date.js"></script> to nvd3/examples/stackedAreaChart.html 
obtained from https://github.com/novus/nvd3.git
2. Open the html file.

What is the expected output? What do you see instead?
 "TypeError: invalid 'in' operand b"
 > if (k in b)
 at nvd3/lib/d3.v2.js Line 3328

What version of the product are you using? On what operating system?
 The latest date.js @Feb 27th 2013
 The latest NVD3 @Feb 27th 2013
 Firefox 19.0

Please provide any additional information below.
 The variable a is 2.2 in this example.
 But index k picks up "_dateElement" because date.js extends Number.prototype.

 d3.interpolateObject = function(a, b) {
   var i = {}, c = {}, k;
   for (k in a) {
     if (k in b) {
       i[k] = d3_interpolateByName(k)(a[k], b[k]);
     } else {
       c[k] = a[k];
     }
   }
   ...

Extending prototype of primitive objects sometimes restricts users to use 
hasOwnProperty() or not to use inherited properties.
Is it possible to add properties with Object.defineProperty instead?

Original issue reported on code.google.com by k1assisi...@gmail.com on 27 Feb 2013 at 5:46

GoogleCodeExporter commented 8 years ago
Not a bug - the hasOwnProperty checks have been considered good practice for 
years. This sort of loop is practically why Object.getOwnPropertyNames was 
implemented. 

Any for..in loop without them when you don't have complete control of the 
incoming object is considered very bad practice. This is a bug in your code, 
not DateJS.

Original comment by darkcr...@gmail.com on 9 Sep 2013 at 8:44