Explain the encapsulated anonymous function syntax

Explain the encapsulated anonymous function syntax

SummaryCan you explain the reasoning behind the syntax for encapsulated anonymous functions in JavaScript? Why does this work: (function(){})(); but this doesn't: function(){}();?What I knowIn JavaScript, one creates a named function like t

AngularJS: Service vs provider vs factory

AngularJS: Service vs provider vs factory

What are the differences between a Service, Provider and Factory in AngularJS? 1:From the AngularJS mailing list I got an amazing thread that explains service vs factory vs provider and their injection usage. Compiling the answers:Servic

What is this weird colon-member (“ : ”) syntax in the constructor?

What is this weird colon-member (“ : ”) syntax in the constructor?

Recently I've seen an example like the following:#include class Foo {public: int bar; Foo(int num): bar(num) {};};int main(void) { std::cout << Foo(42).bar << std::endl; return 0;}What does this strange : bar(num) mean? It som

Does Haskell have a splat operator like Python and Ruby?

Does Haskell have a splat operator like Python and Ruby?

In Python and Ruby (and others as well, I'm sure). you can prefix an enumerable with * ("splat") to use it as an argument list. For instance, in Python:>>> def foo(a,b): return a + b>>> foo(1,2)3>>> tup = (1,2)>>> foo(*tup)3Is there somethi

~= operator in Swift

~= operator in Swift

I recently downloaded the Advanced NSOperations sample app from Apple and found this code...// Operators to use in the switch statement.private func ~=(lhs: (String, Int, String?), rhs: (String, Int, String?)) -> Bool { return lhs.0 ~= r

What's the R equivalent of SQL's LIKE 'description%' statement?

What's the R equivalent of SQL's LIKE 'description%' statement?

Not sure how else to ask this but, I want to search for a term within several string elements. Here's what my code looks like (but wrong):inplay = vector(length=nrow(des))for (ii in 1:nrow(des)) { if (des[ii] = 'In play%') inplay[ii] = 1 e

Should I return bool or const bool?

Should I return bool or const bool?

Which is better:bool MyClass::someQuery() const;const bool MyClass::someQuery() const;I've been using 'const bool' since I'm sure I remember hearing it's "what the ints do" (for e.g. comparison operators) but I can't find evidence of that a

Oracle considers empty strings to be NULL while SQL Server does not - how is this best handled?

Oracle considers empty strings to be NULL while SQL Server does not - how is this best handled?

I have to write a component that re-creates SQL Server tables (structure and data) in an Oracle database. This component also has to take new data entered into the Oracle database and copy it back into SQL Server.Translating the data types

How can I use a Swift enum as a Dictionary key? (Conforming to Equatable)

How can I use a Swift enum as a Dictionary key? (Conforming to Equatable)

I've defined an enum to represent a selection of a "station"; stations are defined by a unique positive integer, so I've created the following enum to allow negative values to represent special selections:enum StationSelector : Printable {

Why is 1===1===1 false?

Why is 1===1===1 false?

In a browser console, entering 1===1 evaluates to true. Entering 1===1===1 evaluates to false.I assume that this is because of the way the statement is evaluated:1 === 1 === 1becomes(1 === 1) === 1which evaluates totrue === 1which is false.

Toggle classname onclick JavaScript

Toggle classname onclick JavaScript

I am nearly there, just a little unsure as to my code setup, I basically want to remove a class on click, and add it back again onclick, then remove onclick, then add onclick. And so on! Here's what I have, it's nearly there, but if there i

Parallel query worker thread was involved in a deadlock

Parallel query worker thread was involved in a deadlock

I run an SQL Server Trace to track some deadlocks issues and I was hit on the head with this comment Parallel query worker thread was involved in a deadlock as a reason for the deadlock.Q1: Does this means that the same query is deadlocking

How can I do 64-bit arithmetic in Perl?

How can I do 64-bit arithmetic in Perl?

I am a perl newbie,Can I simply use 64-bit arithmetic in Perl?For example$operand1 = 0xFFFFFFFFFFFF; # 48 bit value$operand2 = 0xFFFFFFFFFFFF; # 48 bit value$Result = $operand1 * $operand2;I am basically looking for areplacement for the

Pre increment in Javascript

Pre increment in Javascript

I've just encountered a 'feature' in Javascript regarding pre-increments. In all other languages I've used, it goes like I thought it would. E.g. in C++:#include int main(){ int i = 0; i += ++i; std::cout So, ++i doesn't make copy

What does '#' exactly do in C? [duplicate]

What does '#' exactly do in C? [duplicate]

This question already has an answer here: Stringification - how does it work? 2 answers Why i am not getting the expected output in the fol

Boolean true - positive 1 or negative 1?

Boolean true - positive 1 or negative 1?

I'm designing a language, and trying to decide whether true should be 0x01 or 0xFF. Obviously, all non-zero values will be converted to true, but I'm trying to decide on the exact internal representation.What are the pros and cons for each

How can I make conditional binding in knockout.js?

How can I make conditional binding in knockout.js?

I tried this one :But it does not work :) 1:Assuming you have this:function viewModel() { this.itemSelected = ko.observable(true);}ko.applyBindings(new viewModel());​Add a () after itemSelected to get the current value of the observa

Different ways of comparing NSDecimalNumber

Different ways of comparing NSDecimalNumber

For example, with primitive, I'll do thisif ( (x >= 6000) && (x and with NSDecimalNumber, this is what I haveif ( (([x compare:[NSNumber numberWithInt:6000]] == NSOrderedSame) || ([x compare:[NSNumber numberWithInt:6000]] == NSOrder

MongoDB - Difference between index on text field and text index?

MongoDB - Difference between index on text field and text index?

For a MongoDB field that contains strings (for example, state or province names), what (if any) difference is there between creating an index on a string-type field :db.ensureIndex( { field: 1 } )and creating a text index on that field:db.e

PostgreSQL Nested JSON Querying

PostgreSQL Nested JSON Querying

On PostgreSQL 9.3.4, I have a JSON type column called "person" and the data stored in it is in the format {dogs: [{breed: , name: }, {breed: , name: }]}. I want to retrieve the breed of dog at index 0. Here are the two queries I ran:Doesn

Python and Powers Math

Python and Powers Math

I've been learning Python but I'm a little confused. Online instructors tell me to use the operator ** as opposed to ^ when I'm trying to raise to a certain number. Example:print 8^3Gives an output of 11. But what I'm look for (I'm told) is

map of vectors in STL?

map of vectors in STL?

I want to have a map of vectors, (but I don't want to use pointer for the internal vector), is it possible?// define my map of vectormap > map;// insert an empty vector for key 10. # Compile Errormap.insert(pair >(10, vector)); I know that

What is caret symbol ^ used for in css when selecting elements?

What is caret symbol ^ used for in css when selecting elements?

I encountered a css selector in a file like this:#contactDetails ul li a, a[href^=tel] {....} 1:The circumflex character “^” as such has no defined meaning in CSS. The two-character operator “^=” can be used in attribute selectors. Gener

How to query for null values in json field type postgresql?

How to query for null values in json field type postgresql?

I have a json type field in postgresql. However I can't select rows where specific field is null:Code:SELECT *FROM json_array_elements( '[{"name": "Toby", "occupation": "Software Engineer"}, {"name": "Zaphod", "occupation": "Galacti

Bash Multiplying Decimal to int

Bash Multiplying Decimal to int

I read price from user input. When i multiply the input with int like this T="$((PRICE*QTY))"|bc; gives line 272: 12.00: syntax error: invalid arithmetic operator (error token is ".00") or .50 depending on user input. How do i m