<script> function every(arr, fn) { var i, n = arr.length; for (i = 0; i < n; i += 1) { if (!fn(arr[i])) { return false; } } return true; } function each(arr, fn) { every(arr, function(el) { return !fn(el); }); } var a = [3, 4, , 5], b = [ ], c = Object.create(a); each(a, function(el) { c.push(el*el); }); each(a, function(el) { b.push(el*el); }); each(a, function(el) { a.push(el*el); }); </script>
<script> var erde = { radius : 6373, umfang_return : 'return (2*r*Math.PI).toFixed(1)', umfang_new_fn : new Function('r','return (2*r*Math.PI).toFixed(1);'), umfang_anonym_fn: function(r){return (2*r*Math.PI).toFixed(1);} }; /* 1 */ </script>
this.x = 22; var obj = { x : 33, get : function() { return this.x; } }; // definiere Funktionen: var get_fn = obj.get; var get_x = get_fn.bind( obj ); // Verwende diese Funktionen: var arr = [ ]; arr.push( obj.get() ); arr.push( get_fn() ); arr.push( get_x() ); alert(arr);
<script> var str1 = '{"radius":6373,"umfang_return":"return (2*r*Math.PI).toFixed(1)"}', str2 = '{"radius":"6373","umfang_return":"return (2*r*Math.PI).toFixed(1);"}', str3 = '{radius:6373,umfang_anonym_fn:function(r){return (2*r*Math.PI).toFixed(1);} }', a = 3, b = "4", c = a * b, werte, typs, gaia1 = JSON.parse(str1), gaia2 = JSON.parse(str2), gaia3 = eval("(" + str3 + ")"), fn1 = new Function("r",gaia1["umfang_return"]), fn2 = new Function("r",gaia2["umfang_return"]), fn3 = gaia3['umfang_anonym_fn'];//, werte = [ a * b, gaia1.radius, gaia2['radius'], +gaia2.radius ]; typs = [ typeof gaia1.radius, typeof gaia2['radius'], typeof +gaia2['radius'] ], fn_werte = [ fn1(gaia1['radius']), fn2(gaia2['radius']), fn3(gaia3['radius']) ]; /* 1 */ </script>
<script> function templ_expansion(templ_str, templ_items) { var i, j, r = templ_str.split('oO0'); if(r.length !== 1 + 2*templ_items.length) {return '';}; if(unescape) { for (i = 0; i < r.length-1; i += 2) { r[i] = unescape(r[i]); } } for (i = 0; i < templ_items.length; i += 1) { j = 2 * i + 1; r[j] = templ_items[i]; } return r.join(''); } var templ = '<a href="oO0oO0">oO0oO0</a>'; var items = ["javascript:alert('href')","Teste Template"]; document.write( templ_expansion(templ,items) ); </script>