我是JS中"就近声明"以及"允许多次var声明"的拥护者。
我持这样观点源自我对易读性的追求。
看一段代码:
function aFunc() {
for(var i = 0; i < 100; i++) {
doSth(i);我是JS中"就近声明"以及"允许多次var声明"的拥护者。
我持这样观点源自我对易读性的追求。
看一段代码:
function aFunc() {
for(var i = 0; i < 100; i++) {
doSth(i);| function run(code,callback){ | |
| callback = callback || function(r){ | |
| //console.log(r); | |
| }; | |
| function check(f){ | |
| if(f instanceof Function) { |
| //Chrome上能用的 | |
| ["Image", "Audio", "MediaController", "TrackEvent", "Option", "PopStateEvent", "HashChangeEvent", "PageTransitionEvent", "Event", "CustomEvent", "MutationObserver", "Document", "FormData", "XMLHttpRequest", "FormData", "IDBVersionChangeEvent", "StorageEvent", "RTCSessionDescription", "RTCIceCandidate", "MediaStreamEvent", "Notification", "Blob", "FileReader", "ErrorEvent", "Worker", "SharedWorker", "TransitionEvent"] | |
| //标准里有但是还不能用的 | |
| ["RelatedEvent", "DragEvent", "AnonXMLHttpRequest", "RTCPeerConnection", "RTCPeerConnectionIceEvent", "DataChannelEvent", "ClipboardEvent", "FileReaderSync", "BlobBuilder", "FileSaver", "ParGroup", "SeqGroup", "Animation", "PseudoElementReference", "KeyframeAnimationEffect", "PathAnimationEffect", "TimingEvent", "AnimationEvent"] |
| <body> | |
| <style> | |
| .number { | |
| color:purple; | |
| } | |
| .keyword { | |
| color:blue; | |
| } | |
| .string { |
| <div> | |
| <a href="{{protocol}}//{{host}}{{pathname}}">{{protocol}}//{{host}}{{pathname}}</a> | |
| </div> | |
| <script> | |
| function Template(node) { | |
| var prototype = document.createDocumentFragment(); | |
| prototype.appendChild(node); |
| function shuffle(array){ | |
| for(var i = array.length-1; i > 0; i--) { | |
| var rnd = Math.floor(Math.random() * (i+1)); | |
| var tmp = array[i]; | |
| array[i] = array[rnd]; | |
| array[rnd] = tmp; | |
| } | |
| } | |
| function isInOrder(array) { | |
| for(var i = 0; i < array.length-1; i++) |
| var names = [ | |
| /【猪猪字幕组】★4月新番 美食的俘虏Toriko 第\d*话/g, | |
| /【Dymy字幕組】【魔笛_Magi 第二季】【\d*】/g, | |
| /【Dymy字幕組】【東京暗鴉 Tokyo Ravens】【\d*】/g, | |
| /\[OPFans枫雪动漫\]\[ONE PIECE 海贼王\]\[第\d*话\]/g, | |
| /【极影字幕社】 ★物语系列/g | |
| ]; | |
| var request = new ActiveXObject("MSXML2.XmlHttp.6.0"); | |
| request.open("GET","http://bt.ktxp.com/index-1.html",false) | |
| request.send(null); |
有一天,我切了个页面,有个按钮点了以后要跳转到另一个页面,于是我把代码这么写:
window.location = "xxxxxx";结果那个页面lazyload组件有bug,跳过去一片灰色,沟通了半天没解决,经过反复试验,我发现只要我页面的滚动位置不在顶部就会有问题,于是我想办法绕了过去,代码变成了这样:
document.body.style.display = "none";| <pre> | |
| <script> | |
| function levenshtein(a,b) { | |
| var table = [[[]]]; | |
| for(var j = 1; j <= b.length; j++) { | |
| table[0][j] = b.slice(0,j).map(function(e,j){return {action:"insert",element:e,position:j}}); | |
| } |