New answers tagged

1

I do like David Packer's answer on your other question. But to distill it a bit more: Some Business Logic on front end to reduce round trips. But all Business Logic on back end (which, yes, means you will have duplicated business logic) Also, forget about how difficult or not is to implement it on a language. You are taking an architectural decision ...


1

If you have been writing correct code, you will probably be able to turn all var statements into let statements without any semantic changes. let is preferable because it reduces the scope in which an identifier is visible. It allows us to safely declare variables at the site of first use. const is preferable to let. Unless you need to mutate a reference,...


3

Both solution are viable, they simply don't apply to the same use-cases. a) manipulate the DOM via JavaScript : This result in a more heavy first page, but after that you will use less bandwidth, because you will only fetch what you need, and not rebuild and send everything. And in the cases where you don't need to fetch anything, it will be really quick (...


1

A high-level dissection of the code posted: <script type="text/javascript"> Html-element to embed a script in it $("#circle") $ is the jQuery alias for getting the jQuery object which wraps almost all of the stuff jQuery can do. In this case we simply invoke the jQuery object with syntax similar to that of a constructor. This is shorthand for "...


0

It's vitally important that all data is verified on the server when it comes from an untrusted client. (Doubly so with Javascript since hacking tools are built into browsers.) So the question is whether (and how) you should reuse the validation code on the server side or write separate validation code for the UI. Each has trade-offs. Generalize On the ...


4

I'm more interested in answering the questions within your post, or rather the source of your confusion. As for the question in the title: are promises functional? yes they can be. See this page for promises in Haskell, which is the prototypical pure functional programming lanugage. Your confusion as to the side-effecting nature of promises is well ...


1

The benefit of the 1st approach is, as you read your HTML file you also know what happens when the div is clicked (i.e. gotoFamilyPage) without having to dig through your javascript source files, which can get quite large. In other words, your HTML file describes both the structure and behavior of your page. This is better in my opinion. Many people cite ...


1

Rather than think of this as a state of the system I'm inclined to think of it as a few capabilities you either do or don't have access to as a player. Some basic abilities: Copy objects (prototype pattern) Move objects (could be as simple as select object, move player & object, release object) Save objects (as fancy as serialization or as simple as ...


2

If you do not mind recompiling your code, I recommend you to look at TypeScript, developed by Microsoft. It has a C#-like syntax and is a supertype to pure JavaScript, which is compiled to it. Other than that, in combination with modern JS many modern IDEs, I have had a great experience with WebStorm by JetBrains (though it is very likely other IDEs support ...


0

I was able to download the nuget package file and install the package as per http://stackoverflow.com/questions/10240029/how-to-install-a-nuget-package-nupkg-file-locally Then, to setup the jQuery UI properly in Visual Studio 2015, I followed this article: http://www.codeguru.com/csharp/.net/net_asp/a-jquery-ui-based-date-picker-for-asp.net-mvc-5.html ...


0

Since there is no answer, I'll be bold and propose one, even though I don't completely understand your constraints. First, your question contains a mistake. It is not necessary to "buy" a security certificate. StartSSL (offered by StartCom) is free, and Let's Encrypt (https://letsencrypt.org) is free. There are others, too. But if you don't want to use TLS ...


2

You may have to modify the base template you are using for the static page generator to accomplish your goals. Add the javascript libraries/frameworks you need for the individual entries on the main template. Then, as you are creating your entries, add the relevant javascript code to the blog entry to perform the necessary interactions for your readers.


2

I'll give the author the benefit of the doubt and perhaps that is the way things are for Typescript, but otherwise in other environments that's a totally unsubstantiated claim that shouldn't be taken seriously. Off the top of my head, I can think of a variety of situations where passing data via constructor is good, some that are neutral, but none where it'...


-1

I think it is better to defer this kind of decision-making to the framework designer, and use one JavaScript framework that encapsulates this kind of complexity. Nowadays we have AngularJS, JQuery, ReactJS, and so on, doing things without a framework would get you this kind of difficulties.


0

I think it is depends on the context what kind of model that is being discussed here. I don't have Remo's book, but I guess that the model is a kind of service model, which needs to retrieve the data from a remote web service. If that is the case, being a web service model, it is better to pass all the data required as arguments in the web service's methods, ...


3

The benefit of an if expression is its result can be assigned to a variable, like: var result = _if(... Or perhaps its result is directly used in an expression. This isn't the case in your example. All the calculation is done by side effect. You are essentially ignoring the result of the if expressions, so they may as well be statements. I'm all for ...


5

You're asking the classic multi-tenant question. Personally I would - and have - maintain a single copy of the application. It would look up the subdomain in the db to grab a site id, grab the info about the site, and show the relevant content. Templates and images can be stored by putting them into a directory named the same as their subdomain or site ...


2

It is possible, in general, to analyse the parse tree of a function and check a set of constraints that ensure we know if the function is definitely pure: If the function only calls other functions that are pure And doesn't reference or modify any global variables Then it is pure. There is, however, a problem with doing this in Javascript (and many ...


1

Usually you have to query DB every time you render a page. Q1 - Yes, you just have to select all items ordered by created date (well, you don't want to select ALL, but only how much you need for current page - see 'Pagination') Q2 - Yes. Same as above. This might not work exactly as you want, because SQL databases are not search engines. In SQL DB you can ...


2

Essentially, the task is to parse the “right” answer and the answer given by the user. As a result, you will obtain two trees that can be compared. If you're dealing with XHTML, any XML parser in any language will do the trick. If you need to validate HTML which may not necessarily be a valid XML document, then you'll probably need a third-party package ...


0

If you mean that they should be able to import their existing files, then you will have to create a mapping to translate each of the existing Amazon, Newegg, ... formats into your database. For XML feeds that means mapping XPath expressions to your columns. For flat file feeds it means mapping the headers in the flat file to your database columns.


4

Yes, though, not necessarily in the manners you've described. But, there's at least 1 very specific case wherein Google's Closure Compiler optimizes for gzip: Closure Compiler can even tell when two different variables are never used at the same time, letting both share the same name and ensuring that as many variables as possible use very short ...


5

These are both highly unlikely, and I would actively avoid any optimiser which did make these transformations because I would suspect that it might have subtle bugs. Case1: There are two snippets of code that are very similar and very gzip-able, one at the start of the document and the other is beyond 32kb at the end of the document. Does the minifier ...


3

The major benefit is the shorter syntax: var sequence = source.map(t => t.length).filter(s => s > 5); is shorter and more readable than: var sequence = source .map(function (t) { return t.length; }) .filter(function (s) { return s > 5; }); An arrow function expression has a shorter syntax compared to function expressions and ...


3

There are a few differences between arrow functions and anonymous function declarations: Arrow functions don't have a prototype-property. Arrow functions cannot be constructed Arrow functions don't bind a this-value, so you'll get the this-instance of the parent scope Arrow functions don't have access to the special arguments-object For your use case, ...


0

CandiedOrange names the most important single tool for understanding code: the code itself. You can't always trust documentation, and anyway the docs are aimed at people who just want to use the public methods of the frameworks, so you have to run the code, inspect the values of variables or the return values of functions, and use debugging techniques to ...


-1

Minifiers reduce the amount of disk space taken up by a file while preserving it's functionality. They typically do so by deleting technically unnecessary white-spaces, indents, new lines and comments. Then they'll reduce variable names down to letters function helloWorld() { //helloWorld string would be preserved console.log("...


3

Use tests. I read code with my fingers. Print out code and hand it to me and I go cross eyed. Sure you can doodle on it, highlight it, annotate it, and draw cartoons in the margins but mostly, I run the code. I test. Oh sure I can tell you what the odd hello world does. Maybe decode a 3 level deep if else maze. But read enough code and it bleeds ...


0

It turns out that this feature is called time travelling and it comes from flux or redux. I use redux, go check it out: http://redux.js.org


1

There is no clear-cut answer, only a number of options: Choose one particular framework / framework version and keep developing on that for the lifetime of the project. In this case, that means sticking with angular 1 forever. It is not necessarily a bad thing. It is open source, standards-based, reliable and well documented, so essentially you can keep ...


1

Step 1: You write a spec what your function does. Step 2: You implement it according to the spec. Your spec may say that inappropriate arguments lead to undefined behaviour, or lead to an error being reported, or get fixed. Each is fine. Just write a spec and follow it.


4

There are plenty of JSON serialization systems that are more than capable of handling mapping between field names that aren't suitable for use in the language they integrate with. In most cases, they aren't hard to use, and require only a little bit of extra effort. In an ideal world, you wouldn't have to, but if your API already uses dashes, changing it ...


-1

In this case i would store the hashmap of the codes and expressions on the server in cache, where you are already using them for other validation. add a cache expiration to that web call and then in the client side just use the server hashmap result in a for loop for the quick client validation. return the whole hashmap set and store them for some x ...


1

What you have done isn't validation. You've pretty much just said "Guess what the user wanted". Validating it would throw an error if it was outside the range, not randomly coerce it to inside the range. It's perfectly fine for a function to validate its arguments. It's also fine to do what you've done, which is to effectively default them. But those two ...



Top 50 recent answers are included