来考考大家:几个JS题目得输出结果是什么?验证下自己得基础知识吧!
题目一:a、b、c分别输出什么?
function fun(n,o) {
console.log(o)
return {
fun:function(m){
return fun(m,n);
}
};
}
var a = fun(0);
a.fun(1);
a.fun(2);
a.fun(3);
var b = fun(0).fun(1).fun(2).fun(3);
var c = fun(0).fun(1); c.fun(2);
c.fun(3);
//undefined, 0, 0, 0
//undefined, 0, 1, 2
//undefined, 0, 1, 1题目二:列表输出
<ul id="test">
<li>这是第一条alert(0);</li>
<li>这是第二条alert(1);</li>
<li>这是第三条alert(2);</li>
</ul>
<script type="text/javascript">
var elements = document.getElementById('test').querySelectorAll('li'); for (var i = 0; i < elements.length; i++) {
elements[i].onclick = function () {
alert(i);
}
}
</script>//点击每一条都alert:2题目三:变量结果
function A(){ }
function B(a){
this.a = a;
}
function C(a){
if(a){
this.a = a;
}
}
A.prototype.a = 1;
B.prototype.a = 1;
C.prototype.a = 1;
console.log(new A().a);
console.log(new B().a);
console.log(new C(2).a);
------------------------------
结果:
1、undefined、
2. 题目四:
var F = function(){};
Object.prototype.a = function(){};
Function.prototype.b = function(){};
var f = new F();
问:调用f.a( )和f.b( ) 能成功么?
答案:能调用f.a( )但是不能调用f.b( );OK,就先这四题,你是否都会呢?






网友评论文明上网理性发言 已有0人参与
发表评论: