逆方向思考開発
1904 ワード
javascript逆方向思考開発
asp.netは依頼でjavascript call関数を実現します.
//1. : , ;
// : , ;
var l = {};
l.h = function (a) {
// a
if (typeof (a) == "function") {
a(100);
}
}
// : ( )
l.h(function (s) {
console.log("args val = " + s); // :args val = 100
});
//
var o = {};
o.callFn = function (a) {
fn.call(o, a); // o , window.fn
};
function fn(s) {
console.log("args val = " + s);
};
//
o.callFn(100); // :args val = 100
asp.netは依頼でjavascript call関数を実現します.
protected void Page_Load(object sender, EventArgs e)
{
///
Call(" ", en); // :call en method,args:
Call(" ", cn); // : cn , :
}
/// <summary>
/// en
/// </summary>
public void en(string name)
{
Response.Write(string.Format("call en method,args:{0}", name));
}
/// <summary>
/// cn
/// </summary>
public void cn(string name)
{
Response.Write(string.Format(" cn , :{0}", name));
}
/// <summary>
/// ,
/// </summary>
private delegate void CallMethod(string name);
/// <summary>
/// ,
/// </summary>
/// <param name="name"> </param>
/// <param name="method"> </param>
private static void Call(string name, CallMethod method)
{
method(name);
}