ES6箭头函数

目录 Web

第一次见到这箭头=>,我觉得这是很奇葩的写法,因为作为一个老男人来说,会影响阅读和理解代码的速度=_=||
作为ES6新特性之一,箭头函数特点如下
a)简洁
b)this指向
c)rest取代arguments

1. 简洁

var showTips = function(d){[......]

Read more

Capture和Bubble,简明解读addEventListener的第三个参数

目录 Web

Capture

target.addEventListener(type, listener[, useCapture]);

前两个参数很好理解,这里不多说,第三个参数是个布尔值,代表Capture和Bubble
网上解释很多,啰哩啰嗦的,这里用一段代码来解读


<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style="border:1px solid red" id="aa">aaaa
<div style="border:1px solid yellow" id="bb">bbbb
<div style="border:1px solid blue" id="cc">cccc
<div style="border:1px solid green" id="dd">dddd</div>
</div>
</div>
</div>
<script language="javascript">
var dom = document.getElementsByTagName("div");
for(var i =0; i<dom.length; i++){
dom[i].addEventListener("click",function(evt){
console.log(this.id);
},false);
}
</script>
</body>
</html>

addEventListener第三个参数为false,也是最常用的[……]

Read more

cntv.cn视频绝对地址分析

目录 Web

http://dianying.cntv.cn/love/lianaiqianguize/classpage/video/20091221/100120.shtml

这是CCTV电影站一个播放页面地址,打开源码,找到播放器一段,flash player是由JS创建的

var fo = createPlayer("v_player_cctv",928,552);
fo.addVariable("videoId", "20091221100120");
fo.addVariable("articleId", "VIDE0020091221100120");
fo.addVariable("scheduleId", "C13671000001");
fo.addVariable("filePath", "/love/lianaiqianguize/classpage/video/");
fo.addVariable("sorts", "其他,,,爱情,C13671,CCTV-9");
fo.addVariable("sysSource", "discovery");
fo.addVariable("url", "http://dianying.cntv.cn/love/lianaiqianguize/classpage/video/20091221/100120.shtml");
fo.addVariable("videoCenterId","36b502b4ceeb4a6d950955b4bd9e93f8");//视频生产中心id
fo.addVariable("channelId",channelId);//埋码
fo.addVariable("adCall",adCall);//广告
fo.addVariable("isLogin", "y");
fo.addVariable("userId", "001");
fo.addVariable("hour24DataURL", "");
fo.addVariable("isCycle", "false");
fo.addVariable("wideMode", "normal");
fo.addVariable("defaultRate", "low");
fo.addVariable("isAutoPlay", "true");
writePlayer(fo,"myFlash");

createPlayer() 函数在 film_standard2.js 文件,找到swf播放器地址 http://player.cntv.cn/standard/cntvplayer.swf ,下载下来用 Action Script Viewer 6 打开
[……]

Read more