let O = function(name){
this.name = name || ‘world’;
};
O.prototype.hello = function(){
return function(){
console.log(‘hello ’ + this.name);
};
};
let o = new O;
let hello = o.hello();
hello();
这段代码输出hello,注意this的指向
let O = function(name){
this.name = name || ‘world’; //this指向他自己 也就是指向自己
};
O.prototype.hello = function(){
return function(){
console.log(‘hello ’ + this.name); //这里的this指向window
};
};
这里的hello方法是扩展在原型上的this的指向是window,所以是空
所以,调用的时候控制台输出hello,而不是hello world
[ ‘1’, ‘2’, ‘3’ ].map(parseInt) 最终输出为?
A. [ ‘1’, ‘2’, ‘3’ ]
B. [ 1, 2, 3 ]
C. [ 0, 1, 2 ]
D. 其它
http://blog.csdn.net/stronglyh/article/details/47293967
map函数的callback有三个参数value, index, array1
parseInt有两个参数string radix 第一个表示要转的值,第二个表示进制
当参数 radix 的值为 0,或没有设置该参数时,parseInt() 会根据 string 来判断数字的基数。
举例:
如果 string 以 “0x” 开头,parseInt() 会把 string 的其余部分解析为十六进制的整数。
如果 string 以 0 开头,那么 ECMAScript v3 允许 parseInt() 的一个实现把其后的字符解析为八进制或十六进制的数字。
如果 string 以 1 ~ 9 的数字开头,parseInt() 将把它解析为十进制的整数。
提示和注释
注释:只有字符串中的第一个数字会被返回。
注释:开头和结尾的空格是允许的。
map 函数将数组的值 value 传递给了 parseInt 的第一个参数,将数组的索引传递给了第二个参数。
如果省略该参数或其值为 0,则数字将以 10 为基础来解析