wo ye xiang zhi dao

解决方案 »

  1.   

    不太明白什么意思
    function b(){
        this.b1=function(){
            alert(222);
        };
    }
    b.prototype.b1 = function(){
        alert(1111);
    }; var b=new b();
    b.b1();
      

  2.   

    其实我是想实现如下功能。就是在b.prototype中定义个空方法。在b函数内部调用它。如果我在调用b()的页面想在这里做其他的处理。我就在调用页面重写b1()方法,实现某些功能。但是现在的情况是:如果我在b.prototype中定义一个方法而没有通过对象及:var temp = new b();temp.b1();这样调用而是在b1()方法内部调用不能实现。请问怎么实现我这样的思路?
      

  3.   

    举个例子:
    a.js文件
    -----------
    function a(){
    //完成某些操作
    ...//在这里我想调用某空方法,不污染空间。所以不能直接写b();然后在a.js中定义一个空的b();可以理解为这里触发某事件或者调用某方法
    }aa.html文件
    --------
    <script src="a.js"></script>
    <script>
    //这里需要在a捕获在a()中触发的事件或者重载a()中这里调用的方法。完成某些功能
    </script>
    <a href="#" onclick="a();"></a>我现在就是用try{}catch(){}来实现的。想请问有没有更好的实现方式。
      

  4.   

    <script> 
    function b(){ 
    if(typeof b1 == 'function')
        b1();

    function b1(){ 

    </script> 
    <a href="#" onclick="b();">test </a> <br>
    //优雅不? 
      

  5.   

    这不是和try..catch..没什么差别呀?不过这也是一个思路。。
    事件触发是否是这样实现的呢?
      

  6.   

    function b(){ 
    this.b1(); 
    } 直接调用b()而不是new对象的时候里面的this就是指的window对象了 就可以省略 即
    function b(){
        b1();
    }
      

  7.   

    解释很清晰哈。发个实际的代码。某些方法没有。主要是给个实际运用中的例子
    /////////////////////////////部门员工树///////////
    function createDiv( obj, id ){
    var closeDiv = document.createElement("div");
    window.document.body.appendChild(closeDiv);
    closeDiv.id = id + "_close";
    closeDiv.style.position = "absolute";
    closeDiv.style.textAlign = 'right';
    closeDiv.style.zIndex = 100;
    closeDiv.style.visibility = 'hidden';
    closeDiv.style.borderColor = '#FFFFFF';
    closeDiv.style.border = '0px';
    closeDiv.style.borderColor = '#000000';
    closeDiv.style.borderStyle = 'solid';
    closeDiv.innerHTML = "<a href=javascript:_closeDiv('"+id+"'); class='btnCls2' title='关闭' ></a>";

    var topDiv = document.createElement("div");
    window.document.body.appendChild(topDiv);
    topDiv.id = id;
    topDiv.style.zIndex = 99;
    topDiv.style.display = 'block';
    topDiv.style.position = "absolute";
    topDiv.style.backgroundColor = '#FFFFFF';
    topDiv.style.border = '1px';
    topDiv.style.borderColor = '#000000';
    topDiv.style.borderStyle = 'solid';
    topDiv.style.fontSize = '12px';
    topDiv.style.padding = '0px';
    topDiv.style.visibility = 'hidden';
    topDiv.style.overFlow = 'true';

    _moveDiv(obj, id);
    }function _moveDiv(obj, id){ $(id).style.width= getClientWidth(obj) + "px";
    $(id).style.height= getClientHeight(obj) + "px";
    $(id+"_close").style.width= 21 + "px";
    $(id+"_close").style.height= 18 + "px";
    var x = 0;
    var y = 0;
    if(is_ie){
    x= document.body.scrollLeft + obj.getBoundingClientRect().left;
    y=document.body.scrollTop + obj.getBoundingClientRect().top + obj.clientHeight + 3;
    $(id).style.filter = "alpha(opacity=100)";    
    }else if(is_moz){
    x=document.body.scrollLeft + document.getBoxObjectFor(obj).x;
    y=document.body.scrollTop + document.getBoxObjectFor(obj).y + obj.clientHeight + 3;
    $(id).style.opacity = "1.0";
    }

    try{
    $(id).style.left = x+ "px";
    $(id).style.top = y+"px";
    }catch(e){}

    try{
    $(id+"_close").style.left = (parseInt(x) + parseInt(getClientWidth(obj)) -22)+ "px";
    $(id+"_close").style.top = (parseInt(y)+2)+"px";
    }catch(e){}
    }
    function openDiv(obj, id){
    if( $(id) == null ){
    createDiv(obj, id);
    _showDiv(id, true);
    _showDiv(id+"_close", true);
    }
    else{
    _showDiv(id, true);
    _showDiv(id+"_close", true);
    }
    fixSelectBug(false);
    }function _showDiv(id, isShow){
    var x = $(id).style;  
    x.visibility = (isShow) ? 'visible':'hidden';
    }
    function _closeDiv(id){
    _showDiv(id, false);
    _showDiv(id+"_close", false);
    fixSelectBug(true);
    try{
    this.afterClosed();//这里就我问的问题 } catch(exception){}
    }
    function setDivContext(id, context){
    $(id).innerHTML = context;
    }
    var dhtmlTree_list = {};//树对象集合<Object{id 层编号,obj 表单对象,tree dhtmlTree对象(对象的属性方法请查阅官方文档)}>
    dhtmlTree_list.size = 0;//集合大小
    dhtmlTree_list.curIndex;//当前操作Object在集合中的下标
    function getOrgEmp(obj){
    var dhtmlTree = _getDhtmlTree(obj);

    var div_id = dhtmlTree==null? new Date().getTime()+"_div" : dhtmlTree.id;
    var tree_div_id = div_id+"_tree";
    openDiv(obj, div_id);

    if( $(tree_div_id) == null ){
    setDivContext(div_id,"<div id='"+tree_div_id+"' style='OVERFLOW-x:auto;OVERFLOW-y:auto;width:"+getClientWidth(obj)+";height:"+getClientHeight(obj)+";'></div>");

    var url = ajaxPath + "/OrgEmpTree.do";
    var orgEmp_tree_obj=new dhtmlXTreeObject(tree_div_id,"100%","100%",0);
    orgEmp_tree_obj.setImagePath(appPathTmp+"js/dhtmlxtree/codebase/imgs/csh_bluebooks/");
    orgEmp_tree_obj.enableCheckBoxes(1);
    orgEmp_tree_obj.enableThreeStateCheckboxes(true);
    orgEmp_tree_obj.enableTreeImages(0);
    orgEmp_tree_obj.setXMLAutoLoading(url);
    orgEmp_tree_obj.loadXML(url);
    orgEmp_tree_obj.attachEvent("onCheck",function(id, state){
    if( state == "1" )
    orgEmp_tree_obj.openAllItems(id);
    else 
    orgEmp_tree_obj.closeAllItems(id);
    });

    var dhtmlTree = new Object();
    dhtmlTree.id = div_id;
    dhtmlTree.obj = obj;
    dhtmlTree.tree = orgEmp_tree_obj;
    dhtmlTree_list[dhtmlTree_list.size] = dhtmlTree;
    dhtmlTree_list.curIndex = dhtmlTree_list.size;
    dhtmlTree_list.size++;

    try{
    this.afterloaded();
    } catch(exception){}
    }
    }
    function _getDhtmlTree( obj ){
    for(var i=0; i<dhtmlTree_list.size; i++){
    if( dhtmlTree_list[i].obj === obj ){
    dhtmlTree_list.curIndex = i;
    return dhtmlTree_list[i];
    }
    }

    return null;
    }
      

  8.   

    很简单吧 之前定义一个外层的函数
    var afterClosed = function(){};
    function _closeDiv(id){
        _showDiv(id, false);
        _showDiv(id+"_close", false);
        fixSelectBug(true);
        afterClosed();
    }var afterClosed = function(){
        alert('sadsa');
    };