New answers tagged

2

By calling into the Flickity library from your project, you are creating a derived work as far as the GPL is concerned. However, this does not mean that your code must be under the GPL license as well. Your code must be under a license that is compatible with the GPL (which the MIT license is) and people who make changes to your code have to comply to the ...


0

The only way to include the file and use the "open-source licensing" would be to change your license to GPLv3 (otherwise you need the commercial license). Side note: changing your license to GPLv3 does not mean everyone that uses your product has to provide the sources for it (this would only be covered by the AGPL). Therefore the main impact I see is: if ...


-2

Put it on the server. It's faster to write and more secure


1

The process of sharing strings in this manner is called String Interning, and yes, Javascript does it. The way in which string interning is accomplished in Javascript is an implementation detail, and it varies between different Javascript implementations. From a performance perspective, you probably shouldn't be worrying about this unless it becomes a ...


3

Are you over-architecting your app? MVVM is a great way for organizing logic for an application that would otherwise become too complicated. But sometimes it can be overkill. You mention you end up having all the model logic in the ViewModel, and that doesn't seem to be giving you any problems. If there's no practical reason you need to separate your View ...


3

Two things to understand about CORS: CORS is not for authenticating/approving the client, it is for approving a request originating from code executing within a web page on one origin that is destined to another origin (like JavaScript code on domain1.com making an XmlHttpRequest to domain2.com). CORS enforcement is entirely client-side. The server does ...


0

I would not advocate many small modules, their gain is too small. The angular module is really not much of a module system. They provide no real namespacing, they are not strict either, if some other active module 'imports' your dependency it will usually work (as you mentioned) etc. Because of this it will not help you 'document' your dependencies per ...


0

My answer to the question “How do you approach a JavaScript (or any other dynamic language for that matter) project with ~2000 LOC?” I develop PDF form applications. I approach my JavaScript software development project (regardless of source code size) using Petri’s net elements and annotations. The method is not tied to any particular programming language ...


0

JITs are fast for JavaScript, because it's impossible to generate fast machine code when you do not know the type of your variables. When you do not have type information, computations are expensive. For example, x + y is quite complicated if you don't know anything about x and y. They could be integers, doubles, strings, or even objects where this ...


2

Is it significantly easier, faster, better for testing and management, etc. to write the code in C# on the server than in JS on the client? It depends entirely on your Developmental ecosystem. If you write and test lots of JavaScript code, then there might be some gain in doing so. If, however, you spend all your time cutting server-side, C# code and ...


2

Take a look at this article. Javascript array memory management It is similar to .NET memory handling in lists. You always want to set the initial size of a list (or any other collection, for that matter) to avoid suboptimal behavior from performance and from memory usage point of view.


0

Are you familiar with JavaScript closures? The function closes over the other functions so it retains memory of them when you call them in your controller or link function. Consider this: function publicOne() { var x = { val: 5 } publicTwo(x); console.log(x); } function publicTwo(obj) { _privateOne(obj); function _privateOne(v) { obj.val++ ...


0

It's still possible and recommended to write JavaScript in the OOP way that you are used to. Here is a good book that has goes through the most important design patterns in JavaScript. https://addyosmani.com/resources/essentialjsdesignpatterns/book/ There are many JavaScript frameworks out there too where the main goal is to be able to split the code out ...


4

If you are not familiar with JavaScript patterns, I can tell you a lot of large applications and libraries are using Revealing Module Pattern, but there are many other patterns you can use depending to your needs. The Revealing Module Pattern though should give you a nice way to split large files and logically organise them; However when you are working ...


0

I use (Petri’s) Net Elements and Annotations to organize or “to structure” software for my PDF form applications – JavaScript programs that use the Acrobat/JavaScript API. Perhaps it may be useful in your situation. A diagram is used to establish the input-output relations of net elements and two form views of the annotations. Based on the diagram and form ...


0

When working on the code, the different components are typically split up into modules, each one typically implementing a single class, and each one living in a separate file. During production, these files are then bundled together into a single file (hence the thousands of lines of code you're seeing) using something like Browserify (http://browserify.org/)...


1

I am a C++ developer and have begun doing web development lately. I am porting a large desktop app to the web environment. I structure my JavaScript code exactly like I structured C++ code, using same patterns. I have about 25-30 files in all but I will eventually reduce them to 3-5 by clubbing as appropriate and minify them all. For me, it is just the ...


3

A major difference between C++ programs and Javascript scripts is that a C++ program typically runs for a much longer time than a Javascript script. A C++ program with a GUI executes continuously while you are working with the program. A Javascript script on the other hand only executes for a short time to respond to an event and then it ends (even if it ...


1

The JavaScript event handler is executed by the browser engine which also handles rendering of CSS/HTML, user interaction, network traffic and so on. When the engine executes an event handler, uncaught exceptions in the JavaScript code terminates the execution of the event handler code, but does not terminate the browser engine, since this would mean a ...


2

That's not true at all. The JS exception is not uncaught in the slightest. It's simply caught by the browser. A C++ UI library can trivially produce the same effect by calling the onClick handler inside a try/catch. The difference in behaviour has nothing to do with language - it's all library.


0

It varies widely from project to project, of course, but the generally accepted practice is that, for things that are meant to function as libraries or modules, to put them into a single large file and use encapsulation to prevent its internal ("private") interface from leaking to the outside. It is also helpful for developers wishing to use the library/...


0

I would go per feature. So take every issue (bulk edits, inline edits, actions) as a separate task. Then I would setup a new page, so both can be functional at the same time, with the new library. Basic steps Per issue I would do the following: Review the end-to-end tests and check if they are complete so all functionality is covered. Redirect the end-to-...


2

For speed: Measure. However, the temporary variable has the huge advantage that as a reader, I know that all the places using the temporary value use the same actual value. If the same very long expression is used in multiple places, I don't know for sure that (a) the very long expression is actually the same in each place or has a subtle difference (for ...


6

The optimization you are performing by hand is called common subexpression elimination. According to this article, Chrome's V8 has performed this operation since at least 2011; Webkit's JIT also does it; SpiderMonkey, the JS engine in Firefox also does it. I haven't found a good description of the optimization performed by Chakra, Edge's JIT, but the ...


-1

I think you should ask the client to create an api as you think. Even if they are not BRAND, leave it to them. If they fail to create the api, try to guide him with videos and articles. Google has their own documentation/guideline to create an api. Show all the possible ways to do it. Because this is safe. And sometimes when client is rude, try to explain ...


7

Well, on the most basic level, val has fewer characters in it than myObject.someProp.someOtherProp.anotherOne.yetAnother.myValue so, simply parsing it will be (trivially) faster. On the specification level, myObject.someProp.someOtherProp.anotherOne.yetAnother.myValue is the equivalent of myObject["someProp"]["someOtherProp"]["anotherOne"]["yetAnother"]["...


1

const foo = (property) => { return property + 'bar' } In JavaScript, functions are objects. That means they can be passed around and assigned to variables (I mean, other languages support it too and are adapting it more and more, but JavaScript is pretty much build on that). In order to understand ES6 fat arrow functions, it's good to know what the ...


5

const foo = (property) => { return property + 'bar' } How do I read that? Define a constant foo that equals a function which takes an argument, property, and returns property + bar. In general, (...) => { ... } is mostly equivalent to function(...) {...} (there are difference in terms of how this is handled.) So the above is almost ...


2

I recently created a library, json-transforms, exactly for this purpose: https://github.com/ColinEberhardt/json-transforms It uses a combination of JSPath, a DSL modelled on XPath, and a recursive pattern matching approach, inspired directly by XSLT. Here's a quick example. Given the following JSON object: const json = { "automobiles": [ { "maker": ...


-2

wouldn't it take longer to stream the file vs sending whole file at a time? Welcome to the time space tradeoff. Reading a whole file into memory (say as an array or string) is called slurping. It can be a good or bad idea depending on file size, available memory, and how many times you do it at the same time. The alternative is line by line processing (...


-2

I write all my applications in Delphi (As a layer of abstraction), I don´t want and don´t need Javascript or HTML, although the framework generates them for me. We program in layers abstraction since we left assembler. I've also written about these sucking times, of lego applications.


1

You're right that the "type constructor" part of the definition (which Eric described as a type transformation) isn't really relevant in a dynamically typed language. So all you really need are the two functions, unit and bind. In Javascript, the identity monad might look like this: IdentityMonad = { unit: function (val) { return { ...


8

Mason's answer is correct, and yes you should read my series. To emphasize his point more thoroughly: Can a monad be thought of as a function that accepts a value and wraps it such that it meets specific interface and behavioral constraints Yes, but that is not the best way to characterize a monad. You are very close though; we can make small changes ...


0

Because implementations of the language are likely to use primitive types as value types rather than reference types. That is, when you assign a value to a new variable, rather than changing the variable such that a contains a reference to the same object used in the source expression, it might copy the value of that object into the variable (if you know C#,...


0

You have essentially two ways to achieve that. Calling an API When the user claims that he finished the tasks on the third-party site, call the API of this site, asking to confirm that the tasks were already done. If we assume that you trust the third-party and the channel between you and the third-party server, this guarantees you that the user actually ...


1

Can a monad be thought of as a function that accepts a value and wraps it such that it meets specific interface and behavioral constraints that have been found to be useful when working in a functional style? No. The function that wraps a value is unit. If you're trying to see if it makes sense to explain monads as a unit function that returns an ...


6

Eric Lippert wrote a great series on monads that actually explains them in a way that makes sense to non-Haskellers. The whole thing is worth reading, but the basic idea is as follows: A monad is a "type enhancer" that takes a basic type and does something new to it, (such as turning a type T into a sequence like IEnumerable<T>,) with the following ...


2

i) its a function that takes a type and returns a new type i.e. a generic type, i'm not sure it would directly have a use in js as you don't have types iii) would return a different type but in the same monad i.e. you can reproject from m a -> m b it's a minimal definition however there are usually other functions defiend as well e.g. every monad is a ...


0

I don't see the point of watching the model to update, does that mean that every time the user will change one fields you will trigger an update in the database ? How do you handle two list data like country/city then ? Just use what angular give you to handle forms properly. Basically considering we're manipulating an array of object inside a ng-repeat ...


1

Since you are only looking for the update/delete and additions it would be relatively easier to store the status of the object. It would be easier than storing it in 3 different lists, the model binding would be easier. Unit of work pattern not necessary here(client side). When it's time to update the database, you could use the status to update / delete ...


0

Keeping two arrays one for delete and one for insertion seems a good idea to me and these arrays can be easily maintained with $watch where you can check old and new value. For example:- var scope = $rootScope; scope.$watch('petsArray', function(newValue, oldValue) { if ( newValue !== oldValue ) { //Do your changes } }); Sending requests on ...


-1

As pointed out by others, doing the whole thing automatically could introduce bugs. Software development is often about weighing up automating a process with just doing it manually; it often ends up a bit of both. I would recommend doing this particular task manually, perhaps with some search and replace, each file one by one. Get a list of files to change....


0

is it better to create external file for my JS code, or just put it in the html code? It is better to create an external file for your JS code. It is also better to have one or two files that you serve to the client. But, it's also better to have your JS code split across multiples files for maintainability issues. To be able to do this, you can use ...


0

This highly depends on a number of parameters. The update interval should be related to the reaction time expected by the users and the work patterns of the support workers. As you did not provide this information, it's impossible to give a definitive answer. 5 seconds seems unnecessary for typical support desk tasks. 1 minute sounds more reasonable for "...


1

There is no common term (and you don't need one) since they are different categories of things. The quote uses imprecise language: In JavaScript, scope is the set of variables, objects, and functions you have access to. Technically this is wrong, since it confuses variables and values, which are distinct concepts. A scope is a set of variables. A ...


0

"Entities" is a good catch-all term, although it is not widely used because there is not often a reason to refer to such a broad group of things. Indeed, your proposed quotation is wrong: scope limits visibility of names of things, not of named things. So you could say "names", or use the technical term "identifiers".


1

What you are looking for is a simple expression language that can be evaluated from within ECMAScript (which is just another way of saying there exists an interpreter written in ECMAScript). Thankfully, such a language and interpreter already exists: Jexl. Jexl is a simple ECMAScript expression language that features pretty much everything you listed: ...


0

I'd do it recursively, something like this: function removeProp(obj, propToDelete) { for (var property in obj) { if (obj.hasOwnProperty(property)) { if (typeof obj[property] == "object") { removeProp(obj[property], propToDelete); } else { if (property === propToDelete && obj[property] === true) { delete ...


4

Return values and side effects are two different things. void eliminates the return value, it has no effect on side effects: This operator allows inserting expressions that produce side effects into places where an expression that evaluates to undefined is desired. alert() produces a window as a side effect, not a return value. 1+1 is an expression ...



Top 50 recent answers are included