博文

目前显示的是标签为“javascript”的博文

"==" vs. "===" in JavaScript

The identity operator "===" behaves the same as equality operator "==", except there is no type conversion is done on it. For "===" the types must be the same to be considered equal. The "===" operator will not do the type conversion, so if two values are not the same,  "===" will simply return false.  The "=="operator will compare for equality after doing any necessary type conversions. They both do type checking,  but "===" doesn't do type conversion after checking, compared to "==" This check may allow === to exit sooner when types are not the same. In general "===" is faster than "==", but sometimes they are the same (If type are the same).

Escaping in JSP for JSP and JS

Escaping for JSP A JSP page will eventually rendered as HTML content in browser. In that case, lots of character like <, &, > need to be escaped before directly display them on the HTML page. This is when we need the escape for xml for html for JPS page. To escape, you could use this in JSP page <%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> ${fn:escapeXml(myString)} or <c:out value="${myString}"/> Escaping for Javascript Sometimes in JSP page we write Javascript code. The javascript code has its own understand of character like single quote ' and double quote ", this is when we need escape in JSP but for the javascript usage. The best way to do that is create a utility tag libary <?xml version="1.0" encoding="UTF-8" ?> <taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation...

Javascript quick revisit

The new keyword http://htmldog.com/guides/javascript/advanced/oo/ http://stackoverflow.com/questions/1646698/what-is-the-new-keyword-in-javascript CDN - Content Delivery Networks <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script> Browser Object Model (BOM) The window object is supported by all browsers. It represent the browser's window. All global JavaScript objects, functions, and variables automatically become members of the window object. Global variables are properties of the window object. Global functions are methods of the window object. Even the document object (of the HTML DOM) is a property of the window object: window.document.getElementById("header"); same as: document.getElementById("header"); RegEx Syntax var patt=new RegExp(pattern,modifiers); or more simply: var patt=/pattern/modifiers; Prototype property Prototype is a global constructor in J...

JavaScript Object-Oriented Concept Essential Part2

1. Argument (kinda like polymophism in oop) Every function in Javascript has a private varibale called arugments , which can be used to access all the arguments passed to the function without specifying them as parameters when defiend the function. Ex. function testArg() { for(i =0; i } testArg("argmentnaisni1","ajgajdskgl2"); 2. Prototype 2.1 (kinda like static field of class) prototype is a field of all object, ex, you can use: function Square(){;} // Square.prototype.size = 5;// //then all Square object has a field of size which has value 5. // but one can override prototype filed value, ex function Square(){ this.size = 1; } Square.prototype.size = 5; //because prototytpe loads before the object constructor, so it's // //overrided to 1. 2.2 (use like Inheritance) because prototype is shared by all objects constructed by the function, it can achieve inheritance. Ex. function Car() { this. doors = 4; this. speed = 0; this. brake = function(){this.spe...

JavaScript Object-Oriented Concept Essential Part1

1. Everything excpet primitive types in JavaScript is object. 2. Primitive types include Undefined, Null, Boolean, Number and String. 3. JavaScript has three kinds of objects. 3.1 Build-in objects: Array, Image, Date... 3.2 Host objects: window, document, forms.. 3.3 User-defined. 4. Primitive types has associated object. Ex, var stringObj = new String("create String object"); 5. new is used to create objects. 6. this is used to refer the current object. 7. class in Javascript is defiend as function. class field and function is defined by this . Ex, function Cicle(radius){ this . radius = radius; // defined class field, assigned by parameter of constructor this . getArea = getArea; // defined class function, getArea is a function function getArea(){return this. radius;}// still use this to refer current object //the function getArea can also be defiend outside the class, with this. radius always //refer the object who use the funtio...