先看题,别看答案试下吧 ~_~javascript
一、下面的代码输出的内容是什么?css
function O(name){
this.name=name||'world';
}
O.prototype.hello=function(){
return function(){
console.log('hello '+this.name)
}
}
var o=new O;
var hello=o.hello();
hello();
复制代码
分析:
一、O类实例化的时候赋值了一个属性name,默认值为world,那么在实例化的时候并未给值,因此name属性为world
二、O类有一个原型方法hello,该方法实际上是一个高阶函数,返回一个低阶函数,精髓就在这个低阶函数中的this,
注意这里的低阶函数实际上是在window环境中运行,因此this应该指向的是window
复制代码
因此个人答案是:'hello undefined'(但这个答案是错误的,哈哈)html
圈套:却不知原生window是有name属性的,默认值为空
复制代码
因此正确答案应该是:hellojava
二、给你一个div,用纯css写出一个红绿灯效果,按照红黄绿顺序依次循环点亮(无限循环)浏览器
<div id="lamp"></div>
复制代码
/* 思路: 总共三个灯,分别红黄绿,要一个一个按顺序点亮,咱们能够这样暂定一个循环须要10秒中,每盏灯点亮3秒, 那么在keyframes中对应写法就以下所示(红灯点亮时间为10%--40%,黄灯点亮时间为40%--70%,绿灯点亮时间为70%--100%) */
@keyframes redLamp{
0%{background-color: #999;}
9.9%{background-color: #999;}
10%{background-color: red;}
40%{background-color: red;}
40.1%{background-color: #999;}
100%{background-color: #999;}
}
@keyframes yellowLamp{
0%{background-color: #999;}
39.9%{background-color: #999;}
40%{background-color: yellow;}
70%{background-color: yellow;}
70.1%{background-color: #999;}
100%{background-color: #999;}
}
@keyframes greenLamp{
0%{background-color: #999;}
69.9%{background-color: #999;}
70%{background-color: green;}
100%{background-color: green;}
}
#lamp,#lamp:before,#lamp:after{
width: 100px;
height: 100px;
border-radius: 50%;
background-color: #999;
position: relative;
}
#lamp{
left: 100px;
animation: yellowLamp 10s ease infinite;
}
#lamp:before{
display: block;
content: '';
left: -100px;
animation: redLamp 10s ease infinite;
}
#lamp:after{
display: block;
content: '';
left: 100px;
top: -100px;
animation: greenLamp 10s ease infinite;
}
复制代码