最近突然对js有些着迷了,主要也是因为想看看Ajax的缘故,所以在网上看了些关于js的代码,由于看的东西可能有些杂了,结果有些乱,目前主要的问题就是碰到的两种js的编码风格
风格1:
var newformat = {
x : null,
y : null,
 mousedown : function(obj)
{
obj.onmousemove = mousemove;
obj.onmouseup = mouseup;
            
oEvent = window.event ? window.event : event;
x = oEvent.clientX;
y = oEvent.clientY;
},
        
mousemove : function()
{
oEvent = window.event ? window.event : event;
var _top = oEvent.clientY - y + parseInt(this.style.top) + "px";
var _left = oEvent.clientX - x + parseInt(this.style.left) +"px";
this.style.top = _top;
this.style.left = _left;
x =  oEvent.clientX;
y =  oEvent.clientY
},
        
mouseup : function ()
{
this.onmousemove = null;
this.onmouseup = null;
}
};
风格2:
        var x,y;
        function mousedown(obj)
        {
            obj.onmousemove = mousemove;
            obj.onmouseup = mouseup;
            
            oEvent = window.event ? window.event : event;
            x = oEvent.clientX;
            y = oEvent.clientY;
        }
        function mousemove()
        {
            oEvent = window.event ? window.event : event;
       var _top = oEvent.clientY - y + parseInt(this.style.top) + "px";
       var _left = oEvent.clientX - x + parseInt(this.style.left) +"px";
            this.style.top = _top;
            this.style.left = _left;
            x =  oEvent.clientX;
            y =  oEvent.clientY
        }
        function mouseup()
        {
            this.onmousemove = null;
            this.onmouseup = null;
        }
第二种应该是比较常见的风格,这个代码直接写在js文件中就是可用的了,第一种是我根据看到的代码,然后按照自己的理解变了下,但是总是提示错误,无法运行,有些摸不着头脑了
不知道哪位高手能给指点下,这两种风格的js应该如何写才是一致的,比如全局变量定义,方法之间怎么间隔之类的,或是能给说说这两种风格是不是有什么重要的区别不胜感激!