Silverlight.js中临时函数创建

 events: {
    onLoad: Silverlight.createDelegate(scene, scene.handleLoad),
    onError: function(sender, args) {
    var errorDiv = document.getElementById("errorLocation");
    if (errorDiv != null) {
    var errorText = args.errorType + "- " + args.errorMessage;
                                   
    if (args.ErrorType == "ParserError") {
    errorText += "<br>File: " + args.xamlFile;
     errorText += ", line " + args.lineNumber;
    errorText += " character " + args.charPosition;
   }
   else if (args.ErrorType == "RuntimeError") {
       errorText += "<br>line " + args.lineNumber;
       errorText += " character " +  args.charPosition;
   }
   errorDiv.innerHTML = errorText;
   }  
  }
}

// 函数对象的定义和取得

Silverlight.createObject = function(events)
{
  for (var name in events)
    {
        if ( events[name])
        {
            if ( name == "onLoad" && typeof events[name] == "function" && events[name].length != 1 )
            {
                var onLoadHandler = slEvents[name];
                events[name]=function (sender){ return onLoadHandler(document.getElementById(id), userContext, sender)};
            }
            var handlerName = Silverlight.__getHandlerName(events[name]);
            if ( handlerName != null )
            {
                slProperties[name] = handlerName;
                events[name] = null;
            }
            else
            {
                throw "typeof events."+name+" must be 'function' or 'string'";
            }
        }
    }

}

for...in 语句
对应于一个对象的每个 ,或一个数组的每个元素 ,执行一个或多个语句。(可用于遍历对象)

for (variable in [object | array])
statements

参数
variable

必选项。一个变量,它可以是 object 的任一属性或 array 的任一元素。

object, array

可选项。要在其上遍历的对象或数组。

statement

可选项。相对于 object 的每个属性或 array 的每个元素,都要被执行的一个或多个语句。可以是复合语句。

// 在DOM对象Windows对象为临时函数分配名称
Silverlight.__getHandlerName = function (handler)
{
    var handlerName = "";
    if ( typeof handler == "string")
    {
        handlerName = handler;
    }
    else if ( typeof handler == "function" )
    {
        if (Silverlight._silverlightCount == 0)
        {
            if (window.addEventListener)
            {
                window.addEventListener('onunload', Silverlight.__cleanup , false);
            }
            else
            {
                window.attachEvent('onunload', Silverlight.__cleanup );
            }
        }
        var count = Silverlight._silverlightCount++;
        handlerName = "__slEvent"+count;
        
        window[handlerName]=handler;
    }
    else
    {
        handlerName = null;
    }
    return handlerName;
}

你可能感兴趣的:(silverlight)