Tag Info

Hot answers tagged

10

Suppose I have a server-side variable containing JSON, called strJSON that my own code created. Was it created entirely by your code? Are you certain that at no point does it add in a piece of user input? Are you also certain that at no point in the future will it ever be modified to add in data that comes from user input? If you can be 100% sure of ...


10

Let's have a look at the second claim. The JavaScript reactor pattern will always handle concurrency better than any multi-threaded application. To address this claim, I'm going to assume that concurrency in this context equates to scalability, since scalability is one of the primary motivations behind Node.JS. The distinction is subtle, but ...


7

The first difference can be summarized as: this refers to the Instance of the class. prototype refers to Definition. Let's say we have the following class: var Flight = function ( number ) { this.number = number; }; So here we are attaching this.number to every instance of the class, and it makes sense because every Flight should have their own flight ...


6

Doug Crockford discusses let at this point in his recent talk, "The Better Parts". Essentially, let avoids a source of misunderstanding, esp. for programmers with expectations set by languages with block-scope. A var has function scope (it declares a variable that's visible throughout the function) even though it looks like it has block scope. var might ...


6

For Method 1, the function and its symbol is processed by the parser before any code in this file is run. Thus the definition is "hoisted" to the top of whatever scope it is in and the symbol can be used anywhere in the scope it is defined in. Order of declaration within a scope does not matter. So, with the first method, you can do this: hello(); ...


5

It depends quite a bit on the complexity of your application. But the general advantage in using a framework is that they generally target all major browsers, and are quite backward-compatible. Whereas if you rely on HTML5 only some features might only work with the latest browsers or not at all. I just tried <input type="datetime"/> for example. ...


5

If it is truly an ordered linked list, this should be a fairly bad choice because you have to traverse the list one by one until you find the right place to insert the item. In other words O(N). This is ok if the list is small but can get out of hand for big graphs. Usually, what you will need for that kind of stuff is a heap: ...


4

You cannot write only one function. You will still need to have a separate function for each event handler, so the best you can do is to have 3 functions whose total amount of code will be less than what you currently have because it will not contain duplicated code. It will not perform faster, but it will be smaller. So, what you need to do is to extract ...


3

For what its' worth, the article you linked was discussing people who write promise libraries, not people who use them. Your use case seems a bit larger than typical, but as far as I can tell from your description, it's a relatively good fit for promises. Promises are designed to simplify sequencing and composition of asynchronous code. That's certainly ...


3

I would probably start with basic HTML and CSS. It's not hard when you already know how to program. I would start by creating a personal project using HTML, CSS and Javascript. Move on to jQuery if you get familiar with js. I think the problem is that you are trying to achieve a lot at the same time. With that said, there are many resources online nowadays, ...


3

There's really two things to understand: prototypal inheritance has nothing to do with performance at all. The performance issues come from runtime changes to the inheritance structure. prototypal inheritance (and flexible object structures) are not so much inherently slower, as they are harder to optimize. To illustrate the first claim, Ruby would be a ...


2

The latter one is easier to extend and customize, while separating concerns both for the user of the library and the author. For example, if for some reason it made sense in your application, you could very easily create different columns inside different functions. For another example, the user could create their own nifty MyLabel and MyTemplate ...


2

First, I agree with amon's comment. Know what you want to do, then choose the technology. From that point of view, React.js seems to be overkill for a mostly static web. From React's website: We built React to solve one problem: building large applications with data that changes over time. React is a hammer for a specific nail. That would indicate ...


2

It really depends on the structure of the page. If a page has only one purpose and one concern, then you should try to use a single controller so that the code is grouped logically. If there are multiple components on a page with different concerns, then you should absolutely use multiple controllers for the sake of decoupling. For example, consider a page ...


2

Using try/catch for logical branching is not recommended in general, but there are legitimate uses. One example, when you have to query a third party API, and there is no other way to access it. To keep you code more readable, you could encapsulate the try/catch in single, isolated function like function GetSomethingFromThirdPartyApi(parameter, ...


2

You should assume that the server-side dataobjects use their own conventions, and the client-side would have its own. When fetching/posting data, you can set up a model adapter to handle switching between the two. By doing it at this level, each side uses their own conventions that make sense in each's contexts. After fetching your data from an ajax get, ...


2

If the JSON string is encoded entirely under your control, it is exploitable to the extent that your encoding method is broken. That said, you should be safe if you're performing a straightforward serialization using a trusted serializer, like so: var js = new JavaScriptSerializer(); var thingy123 = ThingyRepo.Get(123); var json = js.Serialize(thingy123); ...


2

You make a special message to A that changes it in a way that is not propagated. Its a common idiom where you want general updates to send notifications, but not internal updates or refreshes. For example, I have a dialog that has notification handlers for changes to various controls, but in the initialisation I want to set the controls initial state - ...


1

No, there is nothing wrong with evaluating your own code, if you know for certain it's safe. Too many get caught up in blindly following rules. Evaluation of code in a string seems to really bring out strong opinions for some reason. Evaluation of code in a string is a tool. Learn what it does, how it works, and why it can be unsafe. When you really ...


1

Generally you would have values A and B hidden using a mixin, changeable only through a method setA and setB (or better still by using a setter function). Internally, you would simply assign A or B directly without calling the setA or setB directly, and then call update() which triggers the event. In other words, you'd have setA that assigns A and then ...


1

How did you start to be a backend developer? It must've felt very similar back then. Yet you managed it. I'm sure you'll do the same for frontend. Here's how I'd suggest your learning: Get to know html first. That should be very easy and quick. Learn CSS. Not master it. Get familiar with majority of its properties (no problem if you don't master flexbox ...


1

The short answer is to read a good book on Angular, read it again, and then practice coding, lots of it. That said, if you've never worked with UI, it can be an interesting challenge, because you might be missing some fundamental conceptual information to help you put it all together. What follows assumes that you know what an HTML tag is, and how a form ...


1

JIT compilation tracing techniques often make "hot" objects transformed into instances of hidden (and dynamically created) classes or structures, for which property access becomes as fast as field access in a C struct


1

From reading the cited work I think you are right in assuming the authour is referring to global namespaces as bad practice and they are using fully traversable namespaces as an example of something you should not do as it is under the column "Messy and random". I have not heard this term before and the book does not specify exactly what it is supposed to ...


1

My insight in this matter might not qualify for a full answer, but I think you are comparing to valid approaches, who's differences aren't a matter of style, but of solving different problems. If you fear of trying to do C# in Javascript, maybe you should start by questioning a more essential premise of yours: In my app, obviously I need objects. ...


1

Set the div's style to position: absolute or position: relative. Set the div's children to position: absolute. Position the children using % dimensions. Example (http://jsfiddle.net/o697zdeg/): <div style="position: relative; border: 5px solid red; width: 100px; height: 100px"> <div style="position: absolute; top: 0; bottom: 0; width: 50%; ...


1

I have worked with many designers, some who can work within Rails apps and others who can't. I highly recommend that you only hire designers who are capable enough to integrate directly into the project itself. You will be surprised how valuable a good designer can be once they can integrate their work with the team. Integration will require a little ...


1

In C++, classes makes sense because of the limitations that comes with the C++ philosophy that everything takes a back seat to maximum possibility for performance. You have two false premises inherent in this statement. The first is that classes are a C++ thing. They aren't; the concept is as old as OOP itself, dating back to Simula, the first ...


1

I would mainly try to assess how much the interface will change over time (and you will be the one implementing these changes). As you think it will be subject to more changes I suggest going more to the loose coupling and generic methods direction, because then you can change the client with minimal changes on the server, and vice versa. Similarly if you ...


1

The inline declaration can be easier to read and maintain in simple cases, easier for non-programmer types to understand and maintain, but more difficult to extend or manage dynamic concerns. i.e. in your example, if you want certain columns to only be used in certain circumstances, things start to get ugly and the simplicity and readability are negated in a ...



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