//json方式的面向對象 var obj= { a:12, b:5, c:function(){ alert(this.a)//12 } } obj.c();//12 //命名空間 var miaov={}; miaov.common={ myDel:function(){ } , myAdd:function(){ } }; miaov.fix={ get:function(){ }, set:function(){ } }; miaov.common.myDel()
<script> window.onload=function(){ new Drag('div1') }; function Drag(id){ var _this=this; this.disX=0; this.disY=0; this.oDiv = document.getElementById(id); this.oDiv.onmousedown=function(){ _this.fnDown(); }; }; Drag.prototype.fnDown=function(ev){ var oEvent = ev || event; this.disX = oEvent.clientX - this.oDiv.offsetLeft; this.disY = oEvent.clientY - this.oDiv.offsetTop; document.onmousemove = function(){ _this.fnMove(); }; document.onmouseup=function(){ _this.fnUp(); }; } Drag.prototype.fnMove = function(ev){ var oEvent = ev || event; this.oDiv.style.left = oEvent.clientX - this.disX+'px'; this.oDiv.style.top = oEvent.clientY - this.disY+'px'; }; Drag.prototype.fnUp = function(){ document.onmousemove=null; document.onmouseup=null; } </script>