Weitere ähnliche Inhalte
Ähnlich wie javascript function & closure (20)
Kürzlich hochgeladen (20)
javascript function & closure
- 2. text = Javascript
result = Parsing Text
result = hashmap, hashmap, hashmap,
hashmap, hashmap, hashmap, hashmap,
hashmap, hashmap, hashmap,.....
Bernstein hash hashmap, hashmap, hashmap, hashmap,
Fowler-Noll-Vo hash function hashmap, hashmap, hashmap, hashmap,
Jenkins hash function hashmap, hashmap, hashmap, hashmap,
Pearson hashing hashmap, result
hashmap, hashmap, hashmap,
Zobrist hashing hashmap, hashmap, hashmap, ...
unsigned long hash(unsigned char *str){
unsigned long hash = 5381;
int c;
while( c = *str++ )
hash = ((hash << 5) + hash) + c;
return hash;
}
- 3. <html> ( function window(){
<head> this = window||arguments.callee;
<script> var val0, val1;
var val0 = 'test0';
key0 = 3; val0 = 'test0';
function a(){} this.key0 = 3;
</script> function a(){};
<body> val1 = 'test1';
this.key1 = 4;
<script> function b(){};
var val1 = 'test1';
key1 = 4; } )();
function b(){}
</script>
</body>
</html>
- 4. wkey = "key"; Function['test'] = {
var wVar = "win"; parent: windowEC,
locals:{
function test( a ){ a:null,
var b; b:null
b = ':test'; },
( function(){ arguments:['a'],
var c; body:'.....'
c = ':c'; };
alert( a + b + c );
alert( wKey + wVar );
} )();
}
test( 'hello' ); testEC = {
// hello:test:c a:null,
b:null,
arguments:{
0:'hello',
length:1,
callee: Function['test']
},
this: window,
__parent__:Function['test'].parent,
test: Function['test']
};
for( i = 0 ; i < testEC.arguments.length ; i++ )
testEC[Function['test'].arguments[i]] =
testEC.arguments[i];
- 5. wkey = "key"; testEC.b = ':test';
var wVar = "win"; Function['@35'] = {
parent: testEC,
function test( a ){ locals:{c:null},
var b; arguments:[],
b = ':test'; body:'.....'
( function(){ };
var c;
c = ':c';
alert( a + b + c ); @35EC = {
alert( wKey + wVar ); c:null,
} )(); arguments:{
} length:0,
callee:Function['@35']
test( 'hello' ); },
// hello:test:c this: window,
__parent__:Function['@35'].parent,
test: Function['@35']
};
for( var i = 0 ; i < @35EC.arguments.length ; i++ )
testEC[Function['@35'].arguments[i]] =
testEC.arguments[i];
- 6. wkey = "key"; @35EC.c = ':c';
var wVar = "win";
temp = @35EC.__parent__.a +
function test( a ){ @35EC.__parent__.b +
var b; @35EC.c;
b = ':test'; alert( temp );
( function(){ temp = this.wKey +
var c; @35EC.__parent__. __parent__.wVar;
c = ':c'; alert( temp );
alert( a + b + c );
alert( wKey + wVar ); delete @35EC;
} )();
} delete testEC;
test( 'hello' );
// hello:test:c
- 7. function getValue( $ec, $key ){
var result, temp;
temp = $ec;
while( ( result = temp[$key] ) === undefined )
if( (temp = temp.__parent__ ) === null ) break;
if( temp !== null ) return result;
temp = $ec.this;
while( ( result = temp[$key] ) === undefined )
if( (temp = temp.__prototype__ ) === null ) break;
if( temp !== null ) return result;
throw new error();
}
temp = @35EC.__parent__.a + temp = this.wKey +
@35EC.__parent__.b + @35EC.__parent__. __parent__.wVar;
@35EC.c; alert( temp );
alert( temp );
temp = getVal( @35EC, 'a' ) + temp = getVal( @35EC, 'wKey') +
getVal( @35EC, 'b' ) + getVal( @35EC, 'wVar');
getVal( @35EC, 'c' ); alert( temp );
alert( temp );