Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  Generate first N prime numbers

Recently I am taking an online course named "Startup Engineering" on coursera. There is one assignment which is to use NodeJS to write a program to generate the first 100 prime numbers. This may be very easy for many people. Here I just want to share with you the code to generate not only the first 100 prime numbers. but also any number of prime numbers.Below is the code snippet://Helper class to generate prime numbersvar PrimeProcessor=(function(){ var primeArray=[]; function _isPrime(num){ if(num<=1){ throw new Error("Number cannot be sm...

11,766 5       JAVASCRIPT ALGORITHM NODEJS PRIME NUMBER COURSERA


  Load and execute JavaScript

When we load and execute JavaScript in a webpage, there are many points we need to care about because of its design and feature. There are two features about JavaScript execution in a browser: 1). The JavaScript codes will be executed immediately once loaded;2). When JavaScript codes are being executed, they will block the following contents (including page rendering and other resources downloading). So if there are multiple js files to be loaded, these codes will be executed sequentially.Since JavaScript codes may operate HTML DOM tree, browsers generally will not download js files in paralle...

9,287 0       JAVASCRIPT LOAD ASYNC DEFER EXECUTE


  How to be jQuery-free?

jQuery is now the most famous JavaScript library. There are around 57.3% websites in the world using jQuery, i.e, 6 out of 10 websites are using jQuery. If we only consider those websites which use libraries, then the percentage is even higher which is 91.7%.Although jQuery is very popular, its size is still a headache to many websites maintainers. The uncompressed jQuery 2.0 has a size of 235KB, the size is 81KB after optimization.The jQuery 1.8.3 which supports IE 6/7/8 has a uncompressed size of 261KB, the size is 91KB after optimization.It takes around 1 second to load this file, it may ta...

6,622 0       JAVASCRIPT JQUERY CSS3 ECMASCRIPT


  this in JavaScript in detail

this in JavaScript is always confusing, it is one of the most frequently seen traps in JavaScript. this is not a good design in JavaScript(You can refer some other design flaws of JavaScript here), since it's lazy binding feature, it can be a global object, the current object or.... Some people even avoid using this in JavaScript.Actually if you master how this works, then you will know how to stay away from these traps. Let's take a look at what this points to in below situations.1. In global scope codesalert(this)//windowthis will point to global object(usually it's window in web browsers) i...

3,095 0       JAVASCRIPT THIS BIND


  JSON in JavaScript

When sending an AJAX request to the server, the response can have two formats : XMLHttpRequest.responseXML to access data with XML format and XMLHttpRequest.responseText to access data with string format. XML is the standard data transfer format, but one weakness is it's troublesome to parse and retrieve the data.JSON(JavaScript Object Notation) is a light weight data interchange format, we call it the JavaScript object representation. The advantage of using JSON as the data format is itself is JavaScript. We can first get the data from server with XMLHttpRequest.responseText and then using Ja...

5,284 0       JAVASCRIPT JSON


  Understand this in JavaScript

In JavaScript, this is always pointing to the owner of a function or a method.FunctionLet's check out function first.function introduce() {     alert("Hello, I am Laruence\r\n");}For this function, what does this point to? In JavaScript, a global function's owner is the current page, i.e, the window object. Because its a method of the window object if we define a global function. Now you should know the this will point to the window object in the above function.If we check the introduce property of window:var name = "I am Laruence";function introduce() {  &nb...

3,423 0       JAVASCRIPT THIS EVENT CALL


  JavaScript efficiency catch up

JavaScript is a very flexible language, we can write JavaScript code freely with various styles, different kinds of codes will have different execution efficiency. Here we summarize some tips we get from our development.Efficiency of JavaScript itselfJavaScript has execution context chain, closures, prototype inheritance, eval etc. It brings us some magic features, but it also introduces the performance issue, if we don't use them properly, it will affect the codes execution efficiency.1. Global variableWe may use global variables such as window,document and some custom global variables while ...

3,193 0       JAVASCRIPT EFFICIENCY EVENT DELEGATION EVAL


  Tips and tricks about JavaScript from Google

JavaScript is now a very popular client side language. It's flexible, powerful but easy to make mistakes. So good programming style is better for you to write efficient and readable JavaScript codes. Here are some tips and tricks about JavaScript from Google.True and False Boolean ExpressionsThe following are all false in boolean expressions:nullundefined'' the empty string0 the numberBut be careful, because these are all true:'0' the string[] the empty array{} the empty objectThis means that instead of this:while (x != null) {you can write this shorter code (as long a...

16,022 1       JAVASCRIPT GOOGLE CODING STANDARD