2016年4月25日
2016年4月25日
javascript
数值
1 === 1.0 // true
1 + 1.0 // 20.1 + 0.2 === 0.3
// false
0.3 / 0.1
// 2.9999999999999996
(0.3 - 0.2) === (0.2 - 0.1)
// false原型
Last updated
1 === 1.0 // true
1 + 1.0 // 20.1 + 0.2 === 0.3
// false
0.3 / 0.1
// 2.9999999999999996
(0.3 - 0.2) === (0.2 - 0.1)
// falseLast updated
typeof NaN // 'number'
isNaN(NaN) // truefunction myIsNaN(value) {return value !== value;}parseInt('8a') // 8
parseInt('12**') // 12
parseInt('12.34') // 12
parseInt('15e2') // 15
parseInt('15px') // 15parseInt('1000') // 1000
parseInt('1000', 10) // 1000parseFloat('314e-2') // 3.14
parseFloat('0.0314E+2') // 3.14 parseFloat([]) // NaN
parseFloat('FF2') // NaN
parseFloat('') // NaN
parseFloat('\t\v\r12.34\n ') // 12.34var arr=[1,2,3,4,5];
Array.prototype.sum=function(){
var result=0;
for(var i=0;i<this.length;i++){
result+=this[i];
}
return result;
}
alert(arr.sum());function 构造函数(){
this.属性
}
构造函数.原型.方法=function(){};
var 对象1=new 构造函数();
对象1.方法();var Point = function (x, y) {
this.x = x;
this.y = y;
}
Point.prototype.add = function (otherPoint) {
this.x += otherPoint.x;
this.y += otherPoint.y;
}
var p1 = new Point(3, 4);
var p2 = new Point(8, 6);
p1.add(p2);