捕捉浏览器中的JS运行时错误,主要通过监听window.onerror来实现。但是对于不同的脚本执行方式以及不同的浏览器,能捕获到的信息会有区别。
window.onerror 讲接收3个参数:
msg
:错误描述,比如:a is not definedurl
:出错脚本所在的urllineNumber
:出错脚本的行数
本文将对不同浏览器和不同的脚本执行方式进行测试,并总结这些区别。
function get(uri) { | |
return http(uri,'GET'); | |
} | |
function post(uri,data) { | |
if(typeof data === 'object' && !(data instanceof String || (FormData && data instanceof FormData))) { | |
var params = []; | |
for(var p in data) { | |
if(data[p] instanceof Array) { | |
for(var i = 0; i < data[p].length; i++) { | |
params.push( encodeURIComponenet(p) + '[]=' + encodeURIComponenet(data[p][i]); |
var parser = function(url) { | |
var a = document.createElement('a'); | |
a.href = url; | |
var search = function(search) { | |
if(!search) return {}; | |
var ret = {}; | |
search = search.slice(1).split('&'); | |
for(var i = 0, arr; i < search.length; i++) { |
var obj = { | |
hello: function() { | |
console.log('sofish'); | |
}, | |
world: function(){ | |
console.log('lin'); | |
} | |
}; | |
var fn = function(hello, ooxx, world){ |
function getCommonParent(el1,el2){ | |
var parents1 = []; | |
var el = el1; | |
while(el) { | |
parents1.unshift(el); | |
el = el.parentNode; | |
} | |
var parents2 = []; |
捕捉浏览器中的JS运行时错误,主要通过监听window.onerror来实现。但是对于不同的脚本执行方式以及不同的浏览器,能捕获到的信息会有区别。
window.onerror 讲接收3个参数:
msg
:错误描述,比如:a is not definedurl
:出错脚本所在的urllineNumber
:出错脚本的行数本文将对不同浏览器和不同的脚本执行方式进行测试,并总结这些区别。
Authored by Peter Rybin , Chrome DevTools team
In this short guide we'll review some new Chrome DevTools features for "function scope" and "internal properties" by exploring some base JavaScript language concepts.
Let's start with closures – one of the most famous things in JS. A closure is a function, that uses variables from outside. See an example:
;(function($) { | |
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; | |
function isDOMAttrModifiedSupported() { | |
var p = document.createElement('p'); | |
var flag = false; | |
if (p.addEventListener) p.addEventListener('DOMAttrModified', function() { | |
flag = true | |
}, false); |
// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
// ==/ClosureCompiler==
function xx() {
function hello(name) {
alert('Hello, ' + name);
}
eval('(hello("New user"))')
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |