Tag Info

Hot answers tagged

8

Yours is a common-enough problem that the solution is has a name: an anticorruption layer. This is a layer that translates between an external API with an undesirable structure and the desired internal structure of your app. The idea is to limit the "corruption" of the undesired structure to as small a part of your code as possible. The external API ...


6

It's easy to compile any language, no matter how dynamic, to machine code. It just won't be efficient machine code, since it will usually do a lot of dispatching based on run time type tags and looking up values in hash tables, much like a (bytecode) interpreter. In the simplest case, just compile C code like #include <some_js_vm.h> static char[] ...


5

In fact, Javascript is (inside several major browsers) often "compiled" using Just-in-Time compilation techniques (read about the V8 Javascript engine). But as delnan explained, there are case where it is not worthwhile. AFAIK some implementations use Tracing JIT compilation techniques. And eval could be implemented by calling the compiler. Several Lisp ...


4

There are a few languages that let you specify conditionals like that, but most popular languages require two separate comparisons joined with an &&, like: if (0 <= a && a <= 22.4) However, there are easier ways if you have a long list like this. For one thing, if you have a value like 22.45 it won't hit any conditionals. For ...


3

No. You can't just "invent" syntax. Think about what the compiler has to translate this into: if( 0 <= a <= 22.4 ) First test whether [the integer] 0 is less than or equal to the variable a : this yields a Boolean result. Then try to test whether this [Boolean] result is less than or equal to [the integer] 22.4. Comparing Booleans and integers? ...


3

The answer as someone who has written a significant amount of node.js code at a professional level is yes. As a JavaScript implementation there is no notion of a thread in Node.js. All IO operations are therefore asynchronous. While many of the common node lower level api's do provide an xxxSync variant using them is not preferred and can cause noticeable ...


3

The first form can be generalized like so: A = (function() { return {}; })(); It gives us an object A with no explicit constructor. The object identifies exclusively as Object and the default Object constructor is used. Creating another object from A's constructor yields an empty object: var a_test = new A.constructor(); a_test will be an empty object ...


3

If "spare time" is defined as the time in between the events, then your list format makes it very easy to convert you list of events to a list of spare times: Add midnight to both the start and end of your list Go over the new list and remove any interval of less than 0 seconds (or whatever threshold you want). With your example events, this would give ...


2

Questioned framework is built on top of LLVM, which can be used to compile anything to anything (pretty awesome BTW). Using LLVM as a cpp-to-js compiler should be taken into consideration when existing C++ program (let's say >=100kLOC) is to be ported to the web browser. From a technical point of view, I see 2 cases: Creating nice JavaScript API around ...


2

No. Node.js require() is based on the Common.js module system which uses synchronous loading. Unless you do some server-side preprocessing (bundling) to serve all scripts at once, this is impossible in the browser, where resources are should be loaded asynchronously. You might want to have a look at browserify. However, there is the Asynchronous Module ...


2

The concept you are looking for is called AMD which stand for Asynchronous Module Definition The Asynchronous Module Definition (AMD) API specifies a mechanism for defining modules such >that the module and its dependencies can be asynchronously loaded. This is particularly well >suited for the browser environment where synchronous loading of modules ...


2

Sounds like you're talking about a bot. Bots can be written in any language that can ultimately be run on a computer, meaning if you used Rhino or V8 engine, then the answer to your question is technically yes, though it is likely not what you're thinking. Javascript, in the context of a web browser, lives and breaths on the web page you're viewing. This ...


1

By the fact "Only users with twitter accounts will have access to this, and I will require users to sign-in to be able to access this button" it simply means that the user ALREADY has login, before you start creating the HTML page. Ie, before login, the user will see a form of HTML page, but after login, and at your webserver you have authenticated him via ...


1

You should look at browserify it probably does exactly what you are looking for. You can write code the node way and with a simple command build it all into one file. I think it is a great tool and paradigm. I wrote my little framework using this pattern, it works naively on node and all major browsers including IE 6.


1

I do agree that it should very rarely be used, but I've found a powerful use case for eval. There is an experimental new feature in Firefox called asm.js I've been working with. It allows for a limited subset of the Javascript language to be compiled into native code. Yes, this is very awesome, but it does have limitations. You can think of the limited ...



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