1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Proxy Example</title>
<script>
//Proxy Factory
var proxyFactory = {
createProxy: function(target, invocationHandler){
var proxy = {};
for (var key in target) {
if (typeof target[key] == "function") {
proxy[key] = function(){
return invocationHandler(proxy, target, key, arguments);
};
}
/* we copy only functions
else { proxy[key] = target[key]; }
*/
}
return proxy;
}
};
//Invocation Handler
function handle(proxy, target, method, args){
alert("calling: " + method + " with args: " + args);
var result = target[method].apply(target, args);
return result;
};
//Service
var service = {
operation1: function(arg1, arg2){
return "arg1:" + arg1 + " arg2:" + arg2;
}
};
var serviceProxy = proxyFactory.createProxy(service, handle);
alert(serviceProxy.operation1("aaa", 3));
</script>
</head>
<body>
</body>
</html> |
Gruß Tom




Bereiche
Artikel-Kommentare

Neue Forum-Beiträge
Kategorien





tutorials.de-Systemmitteilung