mblmh9999
mblmh9999
2009-01-07 14:46
浏览 285

在调用方法时把另一个方法的方法名放到参数里有什么用?

[code="javascript"]
function a()
{

}
function b()
{

}
a(b)
[/code]

a 声明时的参数列表里什么也没有,那调用的时候把b方法名放进去干什么?

是不是回调函数, 当A执行完毕后,以返货结果为B的参数调用B?

[b]问题补充:[/b]
看了楼下的说法,可奇怪的是公司那个方法就是什么也没写啊
而且他居然是调用了一个.NET里的方法方法上边写着
[AjaxPro.AjaxMethod]
我觉得可能是不是加了这句话,那个方法就能在javascript里跟.net里共享了,
可那方法确实没有参数啊
[b]问题补充:[/b]
[b][size=xx-large]没有什么都没有[/size][/b]
[code="c#"]
public String getValue_XY()
{
string str_xy = "";
object str_X = "", str_Y = "", tableID = "", deftime = 0, isInArea = 0;

object speed="",direction = "", state = "";
SqlConnection myCon = new SqlConnection(conString);
//SqlCommand myCmd = new SqlCommand("select GID,XMIN ,YMIN from G_res2_4m where GID="+count+"",myCon);
SqlCommand myCmd1 = new SqlCommand("select count(distinct phid) from phone ", myCon);//第一次读取数据库获取记录的条//where做筛选工作
try
{
myCon.Open();
string count = myCmd1.ExecuteScalar().ToString();
COUNT1 = count;
//COUNT1 = int.Parse(count);
//int aa = Convert.ToInt32(count);
//COUNT1 = Convert.ToInt64(count);

}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
myCon.Close();

    }

   // SqlCommand myCmd2 = new SqlCommand("select  PhID,x,y,speed,direction,state,DATEDIFF(second,GPSPositionTime,getdate())as a ,IsInArea from phone WHERE  GPSPositionTime= (select max(GPSPositionTime) from phone)", myCon);//可以添加where语句实现对手机表的筛选工作
    SqlCommand myCmd2 = new SqlCommand("select  PhID,x,y,speed,direction,state,DATEDIFF(second,GPSPositionTime,getdate())as a ,IsInArea from phone WHERE  GPSPositionTime in (select max(gpspositiontime) from phone group by phid)", myCon);//可以添加where语句实现对手机表的筛选工作
    myCon.Open();
    SqlDataReader dr = null;
    dr = myCmd2.ExecuteReader();
    //SqlConnection myCon3 = new SqlConnection(conString);
    //SqlConnection myCon4 = new SqlConnection(conString); 
    while (dr.Read())
    {
        string tableid = "";

        //string str_XY="";//X,Y用"30000,40000"格式表示
        tableID = dr["PhID"];
        tableid = tableID.ToString();
        str_userid += getUserinfo(tableid);

        /*  SqlCommand myCmd3 = new SqlCommand("select userid ,name,sex,idcard,usertype from user_info where phone='" + tableid + "'", myCon3);
          myCon3.Open();
          SqlDataReader dr3 = null;
          dr3 = myCmd3.ExecuteReader();
          string username2="";
          while (dr3.Read())
          {
              object userid1 = dr3["userid"];
              object username1 = dr3["name"];
              object sex1 = dr3["sex"];
              object idcard1 = dr3["idcard"];
              object usertype1 = dr3["usertype"];
              username2 = username1.ToString().Trim();
              int userid2 = Convert.ToInt32(userid1);
              SqlCommand myCmd4 = new SqlCommand("select url from tree where id=(select pid from tree where id ='" + userid2.ToString() + "')", myCon4);
              myCon4.Open();
              SqlDataReader dr4 = null;
              dr4 = myCmd4.ExecuteReader();
              while (dr4.Read())
              {
                  object url1 = dr4["url"];
                  url2 = url1.ToString().Trim();
              }
              dr4.Close();
              myCon4.Close();
              str_userid += userid2.ToString().Trim() + "," + sex1.ToString().Trim() + "," + idcard1.ToString().Trim() + "," + usertype1.ToString().Trim() + ";";
          }
          dr3.Close();
          myCon3.Close();*/
        str_X = dr["x"]; //读取数据库中的GPS坐标
        str_Y = dr["y"];
        deftime = dr["a"];
        isInArea = dr["IsInArea"];
        speed=dr["speed"];
        direction=dr["direction"];
        state=dr["state"];
        str_xy += tableID.ToString() + "," + str_X.ToString() + "," + str_Y.ToString() + "," + username2 + "," + deftime.ToString() + "," + isInArea.ToString() +","+speed.ToString()+","+direction.ToString()+","+state.ToString()+"," +";";
        // str_url += url2 + ",";
    }
    dr.Close();
    myCon.Close();
    //dr.Close();  
    //myCon.Close();
    //str_xy = tableID.ToString()+","+str_X.ToString() + "," + str_Y.ToString();                  
    //count++;
    return Convert.ToString(str_xy);
}

[/code]
[code="javascript"]
//----------------------//这在里边需要指定个回调函数,以接受服务器端处理完后返回客户端结果
function getValue()
{

alert("能到达这里说明更新了");
_Default.getValue_XY(getXY_callback);

}

//-------------------------------------------------------------------------------------
function getXY_callback(response)//这个方法用户接受并处理服务器端返回的结果

[/code]
[b]问题补充:[/b]
[b][size=xx-large][align=center][color=red][/color]我也不知道,公司的人用.NET做的貌似有个什么东西,自动转,可也不是专门编.net的不知道啊.....我还想在里边找json呢,.net干本就用不着,js里连.NET的方法都有!暴汗[/align][/size][/b]

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

6条回答 默认 最新

  • iteye_633
    iteye_633 2009-01-07 15:07
    已采纳

    javascript的函数不一定要声明几个参数就传几个参数,你可以在a里面用arguements来获得参数
    [code="javascript"]
    function a(){
    arguments0;
    }

            function b(){
                alert('b()');
            }
    

    [/code]

    点赞 评论
  • weixin_42513366
    Candyut 2009-01-07 14:50

    不会的。
    你需要这样写:
    [code="js"]
    function a(fun) {

    fun();
    }

    function b() {

    alert("I'm b");
    }

    a(b);
    [/code]

    :D

    点赞 评论
  • bohemia
    bohemia 2009-01-07 14:53

    想到了IoC;

    跟声明个引用或者接口是一样;

    点赞 评论
  • weixin_42513366
    Candyut 2009-01-07 15:07

    他是不是在方法里这么写了:arguments?

    下面是个例子:
    [code="js"]
    function a(){
    alert("I'm a. get args:"+arguments.length);
    arguments0;
    }

    function b(){
    alert("I'm b");
    }

    a(b);
    [/code]

    点赞 评论
  • iteye_633
    iteye_633 2009-01-07 15:09

    :lol: 补充下javascript里的方法也是对象,对象嘛,当然可以当参数来传啦

    点赞 评论
  • weixin_42513366
    Candyut 2009-01-07 15:34

    你第一部分给的是C#代码?
    .Net会把C#代码转成对应JS的吧? :x

    点赞 评论

相关推荐