本帖最后由 wang_137 于 2011-10-20 12:50:31 编辑

解决方案 »

  1.   


    var aa=function(){
     this.say=function(){alert(12)}
    }
    aa.prototype.say1=function(){
    alert(125)
    }
    var b=new aa();
    b.say();
    b.say1()
      

  2.   

    我那样写该怎么改啊,因为我有好多方法要加,我不想每次都写,prototype
      

  3.   

    var aa={};
    aa.say=function(){};
    aa.say1=function(){};
    aa.say2=function(){};
      

  4.   


    function aa(){
    this.say=function(){alert(12)}
    }
    aa.prototype={
    constructor:aa,
    say1:function(){
    alert(125)
    }
    }
    var wori=new aa()
    wori.say();
    wori.say1();
      

  5.   

    楼主理解错prototype了。。只有构造函数才有prototype原型
    刚才你
    aa.prototype={
    say1:function(){
    alert(125)
    }只是给aa添加了一个名为prototype的成员变量
    var aa={
    say:function(){alert(12)}
    }如果想添加say1方法,只需添加一个名为say1的成员变量就可以aa.say1 = functino(){
       //dosth
    }
      

  6.   

    var moveBox={
    version:1.0,
    source:null,
    movable:false,//movable
    mousePosition:null,
    mpSource:null,//mouse position to source
    Client:function(s){//bound element
    moveBox.source=$("#"+s);
    this.register(this);
    }
    }
    moveBox.Client.prototype ={
    getMPSource:function(e){//mouse position to source
    return {
     rx:e.offsetX?e.offsetX:e.layerX,
     ry:e.offsetY?e.offsetY:e.layerY
    }
    },
    getMousePosition:function(e){
    if(e.pageX || e.pageY){
          return {x:e.pageX, y:e.pageY};
           }
           return {
            x:e.clientX + document.body.scrollLeft - document.body.clientLeft,
            y:e.clientY + document.body.scrollTop  - document.body.clientTop
            }
    },
    register:function(o){
    moveBox.source.mousedown(function(e){
    moveBox.movable=true;
    moveBox.mpSource=o.getMPSource(e);
    });
    moveBox.source.mouseup(function(e){
    moveBox.movable=false;
    moveBox.mpSource=null;
    });
    moveBox.source.mousemove(function(e){
    if(moveBox.movable){
    moveBox.mousePosition=o.getMousePosition(e);
    moveBox.source.css("left",moveBox.mousePosition.x-moveBox.mpSource.rx);
    moveBox.source.css("top",moveBox.mousePosition.y-moveBox.mpSource.ry);
    }
    });
    $(document).mouseup(function(){
    if(moveBox.movable)
    moveBox.movable=false;
    });
    }
    }
    var client=new moveBox.Client("move");
    终于完成了,兼容浏览器,但感觉写的有点别扭
    贴出来只是希望大牛们能改的优雅些
      

  7.   

    楼主的代码里面aa是一个实例,并不是一个构造函数。有两个方法可以改正楼主的代码:var aa={
     say:function(){alert(12);}
    };
    aa.__proto__.say1=function()
    {
    alert(125);
    }
    aa.say();
    aa.say1();或者function aa()
    {
    this.say = function(){alert(12);}
    }
    aa.prototype={
     say1:function(){
     alert(125);
     }
    };
    var a = new aa();
    a.say();
    a.say1();具体楼主可以看看关于原型的内容。
      

  8.   

    aa 是对象 没有prototype指针吧
    只有方法才有这个