这是我的部分代码,但朋友说变量(如getStyle,getOffsetWidth,getOffsetHeight,log)不会释放,所以我想知道为什么变量不会释放,以及如何优化它,谢谢!
var Util = (function() {
"use strict";
var getStyle = function(node) {
var style = null;
if (window.getComputedStyle) {
style = window.getComputedStyle(node, null);
} else {
style = node.currentStyle;
}
return style;
};
var getOffsetWidth = function(style) {
return parseInt(style.width, 10) +
parseInt(style.paddingLeft, 10) +
parseInt(style.paddingRight, 10) +
parseInt(style.marginLeft, 10) +
parseInt(style.marginRight, 10);
};
var getOffsetHeight = function(style) {
return parseInt(style.height, 10) +
parseInt(style.paddingTop, 10) +
parseInt(style.paddingBottom, 10) +
parseInt(style.marginTop, 10) +
parseInt(style.marginBottom, 10);
};
var log = function() {
if (window.console && window.console.log) {
window.console.log(arguments);
}
};
return {
getStyle: getStyle,
getOffsetWidth: getOffsetWidth,
getOffsetHeight: getOffsetHeight,
log: log
};
}());