日期:2014-05-16  浏览次数:20444 次

javascript 代码分析
(function() {
var a = {
createNode: function(d, c, f) {
var b = f || document;
var e = b.createElement(d);
if (c) {
a.each(c,
function(g, h) {
if (g === "class") {
e.className = h
} else {
e.setAttribute(g, h)
}
})
}
return e
},
isDOM: function(b) {
return b !== null && b.nodeType === 1
},
isArray: function(b) {
return Object.prototype.toString.call(b) === "[object Array]"
},
isFunction: function(b) {
return Object.prototype.toString.call(b) === "[object Function]"
},
browser: function() {
var b = {};
var c = navigator.userAgent.toLowerCase();
var d = null;
if (d = c.match(/chrome\/([\d.]+)/)) {
b.chrome = d[1]
} else {
if (d = c.match(/firefox\/([\d.]+)/)) {
b.firefox = d[1]
} else {
if (d = c.match(/msie ([\d.]+)/)) {
b.msie = d[1]
}
}
}
return b
} (),
each: function(d, g, f) {
if (d === null) {
return
}
if (d.length === undefined || a.isFunction(d)) {
for (var c in d) {
if (d.hasOwnProperty(c)) {
if (g.call(f || d[c], c, d[c]) === false) {
break
}
}
}
} else {
for (var e = 0,
b = d.length; e < b; e++) {
if (g.call(f || d[e], e, d[e]) === false) {
break
}
}
}
return d
},
indexOf: function(c, d) {
if (c.indexOf) {
return c.indexOf(d)
} else {
var b = -1;
a.each(c,
function(e) {
if (this === d) {
b = e;
return false
}
});
return b
}
},
log: function() {
if (window.console !== undefined && window.console.log !== undefined) {
var d = a.makeArray(arguments);
d.unshift("[YoudaoUtils]");
try {
window.console.log.apply(window.console, d)
} catch(g) {
var b = "[YoudaoUtils.log]";
for (var f = 0,
c = arguments.length; f < c; f++) {
b += (" " + arguments[f])
}
window.console.log(b)
}
}
},
makeArray: function(b) {
return Array.prototype.slice.call(b, 0)
},
prototypeExtend: function(b, c) {
var d = a.isFunction(c) ? c: function() {};
d.prototype = b;
return new d()
},
location: function() {
return !! window.location ? window.location: !!document.location ? document.location: null
},
url: function() {
var b = a.location();
if ( !! b && b.href !== undefined) {
return b.href
} else {
return null
}
},
bind: function(c, b, d) {
if (!d) {
return
}
if (c.addEventListener) {
c.addEventListener(b, d, false)
} else {
if (c.attachEvent) {
c.attachEvent("on" + b, d)
} else {
c["on" + b] = d
}
}
return this
},
unbind: function(c, b, d) {
if (!d) {
return
}
if (c.removeEventListener) {
c.removeEventListener(b, d, false)
} else {
if (c.detachEvent) {
c.detachEvent("on" + b, d)
} else {
c["on" + b] = function() {}
}
}
return this
},
stopPropagation: function(c) {
var b = c || window.event;
if (b.stopPropagation) {
b.stopPropagation()
} else {
b.can