typeof equivalent in scriptsharp
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();
}
精彩评论