anonymous-function

Are Chrome user-scripts separated from the global namespace like Greasemonkey scripts?

痴心易碎 提交于 2019-11-30 21:39:29
I know Greasemonkey scripts are automatically wrapped in anonymous functions isolated in some way in order to prevent them conflicting with scripts in the page. Does the same happen with Chrome user-scripts? Yes, Greasemonkey scripts are normally wrapped in an anonymous function . And, Chrome userscripts apparently are too . But, more importantly, Greasemonkey scripts are usually 1 wrapped in an XPCNativeWrapper sandbox, while Google Chrome converts userscripts into extensions, and they operate in an arena that Google calls an "isolated world" 2 . So, you don't need to wrap your script code in

Performance penalty using anonymous function in Julia

青春壹個敷衍的年華 提交于 2019-11-30 21:20:30
I have noticed that there is a performance penalty associated with using anonymous functions in Julia. To illustrate I have two implementations of quicksort (taken from the micro performance benchmarks in the Julia distribution). The first sorts in ascending order function qsort!(a,lo,hi) i, j = lo, hi while i < hi pivot = a[(lo+hi)>>>1] while i <= j while a[i] < pivot; i += 1; end while pivot < a[j]; j -= 1; end if i <= j a[i], a[j] = a[j], a[i] i, j = i+1, j-1 end end if lo < j; qsort!(a,lo,j); end lo, j = i, hi end return a end The second takes an additional parameter: an anonymous function

PHP closures and implicit global variable scope

我与影子孤独终老i 提交于 2019-11-30 18:48:48
Is there a way that one can implicitly declare top-level variables as global for use in closures? For example, if working with code such as this: $a = 0; //A TOP-LEVEL VARIABLE Alpha::create('myAlpha') ->bind(DataSingleton::getInstance() ->query('c') ) ->addBeta('myBeta', function($obj){ $obj->bind(DataSingleton::getInstance() ->query('d') ) ->addGamma('myGamma', function($obj){ $obj->bind(DataSingleton::getInstance() ->query('a') ) ->addDelta('myDelta', function($obj){ $obj->bind(DataSingleton::getInstance() ->query('b') ); }); }) ->addGamma('myGamma', function($obj){ $a++; //OUT OF MY SCOPE

Closures or create_function in PHP

大兔子大兔子 提交于 2019-11-30 16:22:20
I had made a decision to use closures for my callbacks instead of create_function and as such only support PHP > 5.3 mostly due to the increased debugability and also because I assumed (what is it they say about assumption?) that the overhead of the on-the-fly compilation of the create_function in my situation would probably offset any extra comparisons and such that had to be made within in the function. This may well still be the case (for my application) and further testing is required, but I was interested in the output of this (very) simple test, that shows the create_function method

Closures or create_function in PHP

折月煮酒 提交于 2019-11-30 16:04:52
问题 I had made a decision to use closures for my callbacks instead of create_function and as such only support PHP > 5.3 mostly due to the increased debugability and also because I assumed (what is it they say about assumption?) that the overhead of the on-the-fly compilation of the create_function in my situation would probably offset any extra comparisons and such that had to be made within in the function. This may well still be the case (for my application) and further testing is required,

Delegates, Lambdas, Action, Func, Anonymous Functions

▼魔方 西西 提交于 2019-11-30 14:52:29
I just want to verify my understanding about the following Delegate - a method signature Lambdas - anonymous function Anonymous Function - just that Action - An anonymous function that returns nothing Func - An anonymous function that returns something hmm... they all do similar things, how do you define & know when to use each? sorry, I don't explain well Delegate - it is not a method signature. It is a type which encapsulates a method . Hence a delegate declaration should have a signature similar to the method it wants to encapsulate. When to use Delegate - whenever you want to pass a method

C# ToDictionary lambda select index and element?

落爺英雄遲暮 提交于 2019-11-30 14:37:33
问题 I have a string like string strn = "abcdefghjiklmnopqrstuvwxyz" and want a dictionary like: Dictionary<char,int>(){ {'a',0}, {'b',1}, {'c',2}, ... } I've been trying things like strn.ToDictionary((x,i) => x,(x,i)=>i); ...but I've been getting all sorts of errors about the delegate not taking two arguments, and unspecified arguments, and the like. What am I doing wrong? I would prefer hints over the answer so I have a mental trace of what I need to do for next time, but as per the nature of

How to pass anonymous functions as parameters in Rust?

半世苍凉 提交于 2019-11-30 11:56:26
I've been playing around with Rust the past week. I can't seem to figure out how to pass a function that is defined as a parameter when calling the method, and haven't come across any documentation that shows them being used in that fashion. Is it possible to define a function in the parameter list when calling a function in Rust ? This is what I've tried so far... fn main() { // This works thing_to_do(able_to_pass); // Does not work thing_to_do(fn() { println!("found fn in indent position"); }); // Not the same type thing_to_do(|| { println!("mismatched types: expected `fn()` but found `||`")

Why can't I assign my function reference to a matching variable? E2555 is raised

一曲冷凌霜 提交于 2019-11-30 11:29:29
I'm trying to build an custom comparer which allows the assignment of the comparison function to an internal field. In order to ease the creation of the comparer, I tried to add a constructor-like class function Construct which initializes the comparer. Now if I try to compile the following example, the compiler displays [dcc32 Fehler] ConsoleDemo1.dpr(37): E2555 Symbol 'Result' cannot be tracked I have the following example-code: program ConsoleDemo1; {$APPTYPE CONSOLE} {$R *.res} uses Generics.Collections, Generics.Defaults, System.SysUtils; type TConstFunc<T1, T2, TResult> = reference to

How does variable scope work within the Mocha test framework?

给你一囗甜甜゛ 提交于 2019-11-30 11:24:38
I am a relative newbie to all things javascript, node.js, mocha etc. In my code I have a Unit object that has a disable() that sets the disabled property to true and a isDisabled() that returns the disabled property. It also has a method nextTurnReset() that resets the unit on the start of the next turn. I have written a test suite to test this behavior. I first disable the object and then try to test to see if it is disabled. However, the unit variable inside my first test - which is within the anonymous function passed to the Mocha's it() method - is in the the non-disabled state as I