Skip to content
Advertisement

String index in a JavaScript array

I want to use a specific string in addition to a number to the index of array, I make like this ​ When I print out the tmpArray, it’s empty. Also the size is 0. When I remove the “elem” from the index of the array, it works properly. What should I do? Here’s a real example: http://jsfiddle.net/dfg3x/ Answer JavaScript

Flask url_for URLs in Javascript

What is the recommended way to create dynamic URLs in Javascript files when using flask? In the jinja2 templates and within the python views url_for is used, what is the recommended way to do this in .js files? Since they are not interpreted by the template engine. What basically want to do is: Which is not possible. But naturally, I

What is the “right” JSON date format?

I’ve seen so many different standards for the JSON date format: Which one is the right one? Or best? Is there any sort of standard on this? Answer JSON itself does not specify how dates should be represented, but JavaScript does. You should use the format emitted by Date’s toJSON method: 2012-04-23T18:25:43.511Z Here’s why: It’s human readable but also succinct

AJAX and user leaving a page

I’m working on a chat and I’m trying to figure out how I can detect that the user has left the page or not. Almost everything is being handled by the database to avoid the front end from messing up. So what I’m trying to do is once the page is left for any reason (window closed, going to another

Custom mouse events in backbonejs

What would be a good way of supporting custom mouse events? For example, I currently have: But instead of mousedown, I would like to create a custom event called mousedrag which would be a combination of mousedown and mousemove. Is there any recommended way of adding such a custom event? Answer Since Backbone element events are simply jQuery ( or

What’s the right mindset in using jQuery’s event.stopPropagation()

I have two approaches in mind on how to apply jQuery’s event.stopPropagation(): Optimistic approach – By default, all event handlers are without stopPropagation(). stopPropagation() would be added to a handler only if there’s some unnecessary and undesired behaviour caused by event bubbling. Pessimistic approach – By default, stopPropagation() is added to all event handlers. If there’s some desired behaviour missing

NewLine escape character not working

We know that n is used to feed a new line in JavaScript. How should I use it for an output (in a for-loop): or Neither seems to work. Answer This has nothing to do with JavaScript. In HTML, all whitespace (including newlines) is collapsed and treated as a single space. To do a line break in HTML: Use <br>

Advertisement