开发者

typeof equivalent in scriptsharp

开发者 https://www.devze.com 2023-02-25 05:05 出处:网络
I have some exisiting code in javascript: function setPostData(selector, data) { if (typeof(data) === \'function\')

I have some exisiting code in javascript:

function setPostData(selector, data) {

if (typeof(data) === 'function')

data = data();

$(selector).setParam({'postData':data});

}

how would this translate to scriptsharp (0.7)? esp the if statement... the function accepts data parameter, which can be a dictionary or开发者_运维问答 a function returning a dictionary. if data is a function, this function should be called first, returning a dictionary result...

splitting the function in two function is not the recommended solution, because it is called from other javascript (non scriptsharp).


You could try this:

if (Type.GetScriptType(data) == "function")
{
    Func<object> dataAsFunctor = (Func<object>)data;
    data = dataAsFunctor();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消