Найдите два отличия и пойми почему так получается:
<style type="text/css">
.name {
border: 1px solid;
float: left;
margin: 5px;
text-align: center;
width: 100px;
height: 22px;
}
</style>
<script type="text/javascript">
window.onload = function(){
document.onclick = function(){
(new function(){
this.create = function(name){
var div = document.createElement('div');
div.className = name ? name : 'def';
var width = window.getComputedStyle(div, null).width || div.currentStyle.width;
var height = window.getComputedStyle(div, null).height || div.currentStyle.height;
div.innerHTML = width + ' / ' + height;
div.setAttribute('data-GUIclass','Seeker');
return document.body.appendChild(div);
};
return this;
}).create('name');
};
};
</script>
<style type="text/css">
.name {
border: 1px solid;
float: left;
margin: 5px;
text-align: center;
width: 100px;
height: 22px;
}
</style>
<script type="text/javascript">
window.onload = function(){
var object = new function(){
this.create = function(name){
var div = document.createElement('div');
div.className = name ? name : 'def';
div.setAttribute('data-GUIclass','Seeker');
return document.body.appendChild(div);
};
return this;
};
document.onclick = function(){
object.create('name');
var div = document.getElementsByTagName('div'), i = div.length;
while(i--){
div[i].innerHTML = div[i].clientWidth+'px' + ' / ' + div[i].clientHeight+'px';
}
};
};
</script>