Tag Info

New answers tagged

-1

I want to add, that today, you can use Javascript everywhere, you can build whole applications just with it. Check node-webkit for instance. It uses Node.js along with the webkit renderer to bring web technologies to native applications.


1

Your approach will work. A lot of document management systems use this type of approach. One thing to consider is that you don't need to use both the user uuid and the random item id as part of the string. You can instead hash the concatination of both. This will give you a shorter identifier, and possibly some other benefits because the resultant id's ...


-1

This piece of code might get you started function generateGuid() { var result, i, j; result = ''; for(j=0; j<32; j++) { if( j == 8 || j == 12|| j == 16|| j == 20) result = result + '-'; i = Math.floor(Math.random()*16).toString(16).toUpperCase(); result = result + i; } return result } I ...


6

It is entirely possible although you have to be consistent with your types. The technical term for this is closure. public Action MakeAction(State s) { var me = new Item(); return () => s.Stack.Push(me); }


4

They are not equivalent in their execution order. foo("hi", bar("bye", function() { // do something cool })); This must first evaluate bar("bye", function() { … }), then calls foo("hi", …) with the result of that invocation. As the return value of bar is undefined, you'll get an error when you call that as a function. If you want the callback example ...


1

Consider starting which identifying the core components under a RESTful architecture and then drumming out RESTful XML descriptions of what you want to do. A key component in choosing your stack is scope: who? how many? how often? mobile? tablet? or strictly modern desktop browsers? Starting with a desktop GUI sketch can be a hindrance in developing in the ...


0

Some of the advantages of promises are that they make asynchronous operations a "first-class" entity. They can be transformed, they are composable, and their use also happens to reduce nesting and make handling of async code more analogous to sync code. To me, it is usually more readable to have a chain of promises than nested callbacks. Many modern ...


6

It is usually a good thing to do this whenever possible, but I like to think of this sort of work not as "steps", but as subtasks. A subtask is a specific unit of work that can be done: it has a specific responsibility, and defined input(s) and output(s) (think of the "S" in SOLID). A subtask need not be re-usable: some people tend to think "I'll never ...


5

It's not as strange as you might think. For example, in Standard ML it's customary to limit the scope of helper functions. Granted, SML has syntax to facilitate it: local fun recursion_helper (iteration_variable, accumulator) = ... (* implementation goes here *) in fun recursive_function (arg) = recursion_helper(arg, 0); end I would ...


0

I believe the two main benefits of Promises are: Much more readable code that describes the sequence of operations clearly. I think of "sugar" as saving typing or obscuring (often magic) complexity, whereas in this case, what's more salient is providing greatly increased clarity and therefore more solid, less error-prone code. As Knuth said, code is ...


0

I just had an idea I used once in an example project for a class. It's sort of a workaround, but with proper organisation it could even be called good code. Basically, you would set up a JavaScript object at the start of your page containing all the settings. You would then build your tabs' content in separate pages. Each page will contain both the controls ...


1

First JavaScript doesn't have Classes. Second, your third option seems more rational to me, but it highly depends to your requirements as well. Also you should not be much worried about exposing the helper function. The pros of the solution totally justifies the compromise to me. Third, your time as a developer is valuable; Don't make trivial tasks hard to ...


0

Usually you can store/cache the API results on your server and perform the query your own cache before API. If you couldn't find anything on the cache, or if the result from cache already was expired or too old, then use the API to get the results and store/update the cache again. It could be as simple as a table with with query, result, datetime columns or ...


21

1. Backwards compatibility JavaScript is an implementation of ECMAScript. Most of those functions were introduced in ECMAScript 5 (ES5) however many older browsers which still have a significant enough share of the market do not support these functions (see ECMAScript 5 compatibility table), the most notable of these being IE8. Generally libraries will ...


30

Because different browsers have different implementations and features baked in their JavaScript engine. The same "vanilla-JS" code could run differently on two different browsers, or even two different versions of the same browser. The abstraction layer provided by popular JS libraries is a way around this. Behind the scenes, it works around the different ...


79

Because when those libraries were written, some major browsers did not support those features. Once written and used, these features cannot be removed from these libraries without breaking many applications. (In this case, "major browser" means a browser that still has large market share, which includes older versions of browsers like Internet Explorer, ...


1

Ruby and its commonly used libraries and gems tend to blur the lines between method/property and key/property using attr_accessor, essentially giving an object both a property and getter/setter methods in one line. Either explicitly or implicitly, you'd have def tentacles_count @tentacles_count end def tentacles_count=(n) @tentacles_count = n end def ...


1

Whether Caja has a security advantage depends on what your goals are. These are the main features Caja offers for code sandboxing that all sandboxing methods currently available in browsers do not, as far as I know: Synchronous interaction: you can define APIs which can be called by the guest code and respond immediately — they look like ordinary objects ...


1

Your actual question is kinda more general so it's hard to answer, but your form validation example is a little bit more specific, so I will try to stick with that one. As you said you should always be DRY, as much as possible. That's a good thing to keep in mind as a developer. However you should distinguish between the things that they are similar and you ...


2

First of all, you have not included the legal text that is expected of a file that is released under the LGPL license. From a legal standpoint, that makes it unclear if the LGPL really applies to your library. I would recommend that you follow the guidelines from FSF on how to apply the (L)GPL to your code. With that out of the way, it is also a legal gray ...


3

From my reading of http://www.gnu.org/copyleft/lesser.html and the commentary provided in How can I legally use LGPL javascript in a commercial web site? Yes. That the code is minified in no way absolves the person using it from noting that the license of the code is LGPL and linking to the license. Furthermore, if there are any changes based upon your ...


0

Martin Fowler has an article on using toggles that may be relevant to what you're working on. He starts with: I've seen a lot of names for this concept tossed around: feature bits, flags, flippers, switches and the like. There seems no generally accepted name yet. So the pattern you're looking for appears to be common but not with an agreed upon ...


0

Should I host my site out of Nginx/Apache and use Node as simply a "data" server, funneling data through JavaScript on the client to update the site HTML? Something should be responsible for the port 80. It should be either Nginx/Apache or Node. If you're going to use Node you can use it as your webserver. Should I host it all through Node, adding ...


1

Should I host my site out of Nginx/Apache and use Node as simply a "data" server, funneling data through JavaScript on the client to update the site HTML? Many people recommend this exactly. This article is about yesod, but I think it applies: As fast as Warp is, it is still optimized as an application server, not a static file server. ...


0

Functions are just abstractions for a number of activities you're going to do. You could also call them habits or routines. Our daily lives are built around habits and routines that we follow so we don't have to think too hard about what we're doing. When you wake up, you likely get up; take a shower; eat some breakfast; and brush your teeth. ...


1

Mainstream Javascript engines added JIT (Just In Time) compiling around that time. Mozilla added TraceMonkey to Firefox, Google added Crankshaft to v8 around that time as well. John Resig mentioned TraceMonkey when it was just coming out. These optimizing runtimes improved javascript performance in browsers by an order of magnitude. Before then, ...


3

Imagine a program or a function as a simple set of instructions, perhaps written on paper. Like a recipe or a work order. Now imagine that those instruction allow you to put placeholders in key locations. So while you can have one recipe for frying eggs and another for frying bacon, you could instead have one generic "fry anything" recipe that allows you to ...


2

In programming languages, each bit of code is like a robot that only knows how to do one simple thing. Other robots can give it stuff to work on, and take finished stuff from it, but it still only knows how to do that one thing. With higher order functions, you can hand robots other robots. And those robots you hand them can be holding robots too. This ...


0

You can use JQuery. In this example, you can't enter 'w' into the text box. <input type='text' id='t' value='texttext' /> $("#t").keypress(function(e) { if (e.which === "w".charCodeAt(0)) { e.preventDefault(); } });


4

You're a little confused about terminology and what factors are relevant, as people mentioned in the comments. Let me just address the syntax of Erlang, which is a functional language. It has more operators because it does more. It needs a ++ because it was already using + for something else. It uses ++ instead of a word like concat because the language ...


4

It sounds like your observations about syntax are merely preferences, so let me make some observations of my own. First of all, let me state equivocally that syntax does matter. The simplest syntax of all is Lisp: (defun fib (n) (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2))))) Because code is essentially data in Lisp, lisp can understand ...


1

Screen flickering suggests that you have areas of the screen being redrawn, and that the mode is 'A drawn over B' where A and B are visually quite different. After a certain time suggests that there is the execution of JavaScript code with memory allocation leading to garbage collection, so that the redrawing is slowing down and becoming more visible. ...


1

Does this happen not only on your machine, but on others too? Try to put a console.log('executing content load') in the callbacks for dynamically loading the content. Then check in the developer console of your browser of choice if those callbacks are fired many times. If that is the case, try to find out why those callbacks are fired so eagerly. Without ...


1

What is the benefit of doing things this way rather than importing separate scripts? I would think the separate scripts would make the page itself load quicker. In a word "caching" your browser can cache the downloaded script file and use it again and again without recourse to the network. If you embed your javascript in HTML then it gets downloaded with ...


2

How are they compressing (or how would one compress) the javascript? Should I use YUIcompress on every page call? I usually use something like UglifyJS prior to uploading my script files. Doing it every single time you have a page call doesn't seem very efficient. It's preferable to already have the JavaScript minified/compressed before you make it ...


0

There may also be issues with complying with accessibility legislation e.g. for blind users. I don't know how well screen readers cope with Flash - I don't imagine very well.


0

My opinion is that it's better to make system behavior decisions server-side (in your case linq). I like to assume that all of my client code could be hacked by an evil person who is up to no good. If that code is nothing but presentation, then I'm a little safer. What would happen if evil client code reported that many fields had changed when they ...


5

JSON representation can be dense, certainly denser than a flat list of properties, so memory exhaustion and denial of service may be slightly easier. Other than that, assuming your JSON parser is bulletproof, you're left with basically the same attacks that can be directed at a form-data or query-string based entry point, primarily various kinds of string ...


3

Martin Fowler describes one approach to this as the Segregated DOM, where you separate your DOM JavaScript from your page logic JavaScript. Application Logic <----> DOM Manipulation <----> DOM / HTML


3

Based on your requirements, do include it. Robert Harvey has given good reasons as to why. I am going to talk about how. You said the polyfill is tiny. But if you include it again, and several other libraries your users are also including on their pages add it, you will be adding to the issue. You can take a couple of approaches. The first approach would ...


3

Your decision will be based on the following factors: Is there a well-known, stable, reliable Javascript library that contains the polyfill function I need, available in its externally-published API? Is it worth the costs* to require the users of my library to take a dependency on that other library to get the required polyfill function that my library ...


1

As others have said, if you have JavaScript that interacts with the DOM, then there is going to be some coupling. The question is about the tightness of coupling. Tight coupling between JavaScript, HTML and CSS typically happens when: JavaScript functions run the same hardcoded DOM queries multiple times, rather than binding elements to aliases once and ...


2

No, using class, element, and ID selectors client-side should not be avoided. The syntax is used because CSS selectors are very mature and well-established domain language, and having a common design makes it far easier to share a common logical model of a page between program and design, which is a very, very good thing. While it is possible to mis-use ...


29

There is no way to avoid that. They are coupled because they interact with each other. If your javascript intends on doing any kind of DOM manipulation, then it needs a way to reference the DOM. There are various conventions for it. The Level 2 DOM API provides the getElementById, getElementByTagName, and getElementsByName methods. To this day these are ...


8

If you're willing to forego the interactivity that you get, you can avoid Javascript entirely. Frameworks like ASP.NET MVC are very good at serving up pages that only contain HTML, CSS, and a SUBMIT button. OK. Maybe that's a bit extreme. Decoupling in a web application already occurs at many levels. REST applications allow you to define your ...


0

If you want a request sent after a confirmation dialog is shown it's up to you, via client code, to do that. The browser will not take any initiatives for you there. On its own it only can tell it must send a request when a form is submitted, a link is clicked or a new address or search query is submitted. That's it. Other than that, it never knows. So the ...


0

Why? JavaScript doesn't have Block Scope, that should explain why things should hoist to the top. Is it useful? If you prefer this: var someVariable = someVariable || {}; Instead of this: if ( "undefined" !== typeof someVariable ) { someVariable = someVariable; } else { someVariable = {}; } Then it is useful. Even if you don't notice it! ...


15

Hoisting describes a feature of how Javascript is interpreted by the browser, and isn't so much a feature to be used. When interpreting Javascript, browsers scope function-level variables at the beginning of the function. Example: function AddTwoAndTwo() { var two = 2; var result = two + two; return result; } In the posted code, both ...


8

I've never heard the term "hoisting" used. If you are referring to this usage of hoisting by Ben Cherry: http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html, then from what I can gather, he is simply echoing Douglas Crockford from Javascript: The Good Parts, and saying that you should never use hoisting. His assertion at the end is that all ...


1

That's generally correct, not just for Javascript but for any language. Javascript just happens to be the de facto language for doing such. You could use most any language for manipulation of page elements. This is what CGI is. Javascript just happens to "live" in the browser rather than on a server. This makes things like AJAX possible, which in turn makes ...



Top 50 recent answers are included