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

 JAVASCRIPT


  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,458 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,224 0       JAVASCRIPT EFFICIENCY EVENT DELEGATION EVAL


  One thought about JavaScript exception handle

Due to network, browser and cache issues, the JS executed in production may produce different results from the testing environments. Sometimes they may produce exceptions. Front-end developers may encounter this kind of exceptions frequently. But how to log and use them is seldomly considered by them. Actually, exception handling includes two steps : log and use.1. LogRegarding to log error, this is relatively convenient, since in each browser, there is one interface called window.onerror.window.onerror =function(errorMessage, scriptURL, lineNumber){ alert(errorMessage, scriptURL, lineNumber)...

2,242 0       EMAIL LOG EXCEPTION JAAVSCRIPT


  noConflict mechanism in jQuery

Many JavaScript frameworks like to use $ as function or variable name, jQuery is one of them. In jQuery, $ is just a reference to window.jQuery, so even if $ is deleted, window.jQuery will still be available to ensure the whole library can work normally. jQuery API design takes fully consideration of multiple frameworks conflicts, we can use jQuery.noConflict function to easily handle control.jQuery.noConflict accepts one optional boolean parameter[1] to determine whether to hand jQuery object itself when handing the $ reference.jQuery.noConflict([removeAll])By default, when executing noConfli...

4,256 0       JQUERY NOCONFLICT $


  JavaScript cross domain request solution

1. What is cross domain?We may often using AJAX to request data from other domain, now we will have cross domain request issues. It's because JavaScript only allows to request data from the same domain because of security consideration. In short, same domain strategy means a piece of code can read data from the same source, the same source here means the combination of the same domain, protocol and port number.For example:URLDescriptionAllow communication?http://www.a.com/a.js http://www.a.com/b.jsSame domainYeshttp://www.a.com/lab/a.js http://www.a.com/script/b.jsSame domain differe...

4,357 0       SECURITY AJAX CROSS DOMAIN


  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,082 1       JAVASCRIPT GOOGLE CODING STANDARD


  Understand JavaScript prototype

For an front end programming language like JavaScript, if we want to understand its OOP feature, we need to understand its objects, prototype chain, execution context, closure and this keyword in deep. If you have a good understanding on these concepts, you should be confident that you can handle this language well.The inheritance in JavaScript is not class inheritance like Java, but it adopts another mechanism-- prototype inheritance. The key to prototype inheritance is the prototype chain mechanism which realizes one of the most important feature of OOP--inheritance.In this article, we will ...

3,204 0       JAVASCRIPT PROTOTYPE __PROTO__


  About JavaScript source map

Last week jQuery 1.9 was released. This is the last release before jQuery 2.0. It adds many new functions, one of them is the source map.By accessing http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js , you can scroll to the last line and you will see below line : //@ sourceMappingURL=jquery.min.mapThis is source map, it is a separate file and it is put at the same directory as the source file. You can click here and see what it looks like. It's an very useful function, we will talk more about it here.1. Start from source code transformationJavaScript source codes now ...

6,143 0       JAVASCRIPT SOURCE MAP JQUERY