Tag Info

Hot answers tagged

38

They already have a term for that in the Javascript world. They are called Immediately Invoked Function Expressions (IIFE). What it is IIFE functions are not given a name. Instead, they are executed once as the interpreter comes across them: var area = function() { var width = 3; var height = 2; return width * height; }(); The final ...


7

Is there a technique for unit testing both components in one run? That would actually be the opposite of unit testing - unit testing, especially in TDD style, means to test your components in isolation. Thus the answer is yes, "run separate test suites for the JS and PHP sections", otherwise it is not unit testing and not TDD. Of course, automated ...


6

Generally speaking, the conditional operator is intended to make an if statement with a value. w = x ? y : z. Thus, if you're using it for side effects, it's counter-intuitive. Valid, but counter-intuitive; and remember that you're writing code for your teammates to read.


4

What do you call a callback function that accepts some parameters, but they are not explicitly declared when calling the function? I'm not sure. In certain cases an object's method may be considered to have the object itself as an implicit parameter. But there are no function calls with implicit parameters your examples. With a callback, you don't pass ...


3

It depends. When A and B obtain their data each on its own, this has the advantage that both are independent from each other, and A may be used without B, and B without A. The disadvantage is that you might need to pull the same data over the network twice, and that the data displayed by A and B might not be always consistent because the content changed ...


3

I'm not familiar with the specific site you're integrating with, so this answer is about the general approach to this kind of problem. The best thing to do in this situation is ask the administrators of the site in question how they want you to do it. Of course, this isn't always possible, so if you can't do this, then the following approaches are in rough ...


2

What do you call a callback function that accepts some parameters, but they are not explicitly declared when calling the function? I'm not sure what you're talking about. function(data) explicitly declares a parameter named data for the anonymous function. private void MyCallBack(IAsyncResult ar) explicitly declares a parameter named ar with the type ...


2

I would have to agree with you that generating javascript ought to be the same whether from the 32-bit or 64-bit SDK. Further, I fail to see the project manager's concern about 32-bit clients visiting your site. However, it is conceivable that despite all intentions to the contrary, the 32-bit and 64-bit software (SDK) behave differently (i.e. one has a ...


2

The important thing is to distinguish between TDD and ATDD. The AT there stands for "acceptance tests", and this refers to development where you first start with an acceptance test, which is likely to test the entire stack. This is also sometimes called "outside-in test driven development". When people talk about TDD, the "T" there probably refers ...


2

Named functions have a name, that is you can refer to them by their name. In JavaScript: function hello() { console.log("Hello, World!"); }; You refer to them by their name for example to pass them as parameters to other functions. For example, in the following code, you use the name hello of the previously written function to pass it to doSomething: ...


1

A couple of cases, that are not assignments, where I find ternary operators useful are: In function arguments: in my opinion f( e1, .. cond ? em : dm, .. en); is less error prone than if ( cond) f( e1, .. em, .. en); else f( e1, .. dm, .. en); When you want to call one function or another with identical arguments: again I find (cond ? f : g)( /* ...


1

My general first recommendation about this, is don't use it, it makes programs harder to read with no real upside. The primary exception being constructor functions. In a library you can just leave this of a callback being global/undefined, anything you would pass as a this value may as well be passed as another parameter.


1

This would work, but it's a very unusual way of accomplishing this task, so I would avoid it unless it's meant to be part of a learning exercise in how prototypes work. Just to make sure we're on the same page, the "typical way" I have in mind is this: var Switch = function() { this.state = "ON"; }; Switch.prototype.switch = function() { ...


1

The correct usage of prototypes in JavaScript depends on what you want to achieve. The understanding of what a prototype is and why it exists is a very good question. Prototype exists in JavaScript, because objects do not have classical inheritance based on a Class, like in traditional languages. In JavaScript, objects are pairs of keys and values. They ...


1

Definitely take a look at Waterline.js. It has support for dozens of databases, including MySQL, PostgreSQL, MongoDB, and others. It exposes a uniform query interface that works across relational and non-relational ("nosql") databases Documentation: http://sailsjs.org/documentation/concepts/models-and-orm


1

You could use a hash. If you had an inline script like this: <script>alert('Hello, world.');</script> You can hash it and specifiy it in your Content-Security-Policy header. Content-Security-Policy: script-src 'sha256-sha256-qznLcsROx4GACP2dm0UCKCzCG-HiZ1guq6ZZDob_Tng=' There's also a mechanism for using a nonce: <script ...


1

An Activation object is the object used to hold the properties that describe the environment and scope of an executing function. It is on this object that function arguments for example, are stored. By definition, to ACTIVATE something is to cause that thing to act or FUNCTION. So when you hear 'Activation object', think 'FUNCTION' object, or better yet, the ...



Only top voted, non community-wiki answers of a minimum length are eligible