var FThread= new function(){
Version: 5
Description: 'creates a wrapper for function that allows you to not be afraid of exceptions in'
License: 'public domain'
Implementation:
var FThread= function( proc ){
var thread= function( ){
var res, self= this, args= arguments
var starter= new XMLHttpRequest
starter.onreadystatechange= starter.onabort= function( ev ){
starter.onreadystatechange= starter.onabort= null
res= thread.proc.apply( self, args )
}
//console.dir( starter )
starter.open( 'get', '#', true )
starter.send( null )
starter.abort()
return res
}
thread.proc= proc
return thread
}
//Export: return FThread
Usage:
var inverse= FThread(function( a ){
if( a === -1 ) (void 0)()
if( a === 0 ) throw Error( 'division by zero' )
return 1/a
})
alert([ inverse( -1 ), inverse( 0 ), inverse( 1 ) ])
// alerts ",,1" and two exceptions in console log
}