我正在尝试创建一个变量,无论何时调用都会返回当前值。示例应该更好地描绘这一点:
var image = jQuery('.myimage');
var currentWidth = function(){ return image.width(); };
// now, in any later place in the script the above variable
// should contain the current width without necessity to update this
// variable over and over again each time (we assume that the width
// of an image is changing as the script executes and this variable
// should always contain the CURRENT width and not the one set at the
// beginning).
因此,每当宽度发生变化时,我都希望能够获得当前宽度。这样的事情可能吗?上面的示例为我返回一个字符串,而不是当前值。