JavaScript
共 17 篇文章
JS DES加密
原创转载请注明出处: http://agilestyle.iteye.com/blog/2382089 有一个这样的业务场景,两个不同的平台进行数据交互,一级域名提供网页消息数据,二级域名提供用户相关数据,因为涉及平台交互,所以防止JS跨域劫持,需要对前端的用户相关信息进行加密传输处理。 这里采用 crypto-js 进行DES加密,具体思路:前端进行用户相关信息DES加密处理后,传输给后端进行DES解密,其中对称加密的 key 需要定时刷新(比如采用Spring定时器存入Redis),所以每次提交form的时候,需要首先从Redis中取出最新的 key(可以提供一个取 key 的接口),取…
2017-06-29 15:41 · JavaScript
JS实现键盘Enter键提交表单
原创转载请注明出处: http://agilestyle.iteye.com/blog/2381878 编写JS脚本 function enterDown(e){ var keycode = 0; if(isFirefox()) { keycode = e.which; } else { keycode = e.keyCode; } if (keycode === 13 ) { //回车键是13 if(googleFlag) { loginWithGoogle(); // 需要google验证登录 } else { loginWithoutGoogle(); // 不需要google验证登录…
2017-06-28 15:01 · JavaScript
JS Typical Questions
原创转载请注明出处: http://agilestyle.iteye.com/blog/2370610 Scope (function() { var a = b = 5; })(); console.log(a); console.log(b); ReferenceError: a is not defined 5 Note: a 被关键字var声明,说明 a 是这个函数的局部变量,所以函数外打印 a, 会显示错误 not defined, b 没有被关键字var声明,JS默认 b 是一个全局作用域,所以函数外打印 b,会显示 5 另外如果使用 'use strict'; 会直接报错 (f…
2017-04-21 10:56 · JavaScript
JSON.parse() & JSON.stringify()
原创转载请注明出处: http://agilestyle.iteye.com/blog/2352232 JSON.parse() Demo var str = '{"username":"nodejs", "password":"23"}'; console.log(JSON.parse(str)); Console Output JSON.stringify() Demo var str = {a: 1, b: 2, c: "test"}; console.log(JSON.stringify(str)); Console Output
2017-01-10 14:16 · JavaScript
JavaScript Object Properties —— Preventing Object Modification
原创转载请注明出处: http://agilestyle.iteye.com/blog/2341901 Preventing Object Modification When you want to lock down an object’s properties in some way, there are three different ways to do so. Preventing Extensions If you use Object.preventExtensions() , objects will no longer allow properties to be adde…
2016-11-30 16:52 · JavaScript
JavaScript Object Properties —— Property attributes
原创转载请注明出处: http://agilestyle.iteye.com/blog/2341900 Property attributes All properties have several associated attributes. These attributes define how the properties work. Common Attributes Both data and accessor properties have [[Enumerable]] and [[Configurable]] attributes. var person1 = { name: …
2016-11-30 16:37 · JavaScript
JavaScript Object Properties —— Enumeration, Types of Properties
原创转载请注明出处: http://agilestyle.iteye.com/blog/2341899 Enumeration All object properties are enumerable by default , which means that they will appear in a for-in loop or be retrieved by Object.keys(). var listProperties1 = function (object) { var property; for (property in object) { console.log("Name…
2016-11-29 21:16 · JavaScript
JavaScript Object Properties —— Define, Detect, Remove
原创转载请注明出处: http://agilestyle.iteye.com/blog/2341895 Defining Properties There are two basic ways to create your own objects: using the Object constructor and using an object literal. For example: var person1 = { name: "Nicholas" }; var person2 = new Object(); person2.name = "Nicholas"; person1.age …
2016-11-29 20:46 · JavaScript
JavaScript Object Methods
原创转载请注明出处: http://agilestyle.iteye.com/blog/2341782 The this Object Every scope in JavaScript has a this object that represents the calling object for the function. In the global scope, this represents the global object (window in web browsers). When a function is called while attached to an object…
2016-11-29 14:06 · JavaScript
JavaScript Function Overloading
原创转载请注明出处: http://agilestyle.iteye.com/blog/2341742 Function Overloading A function signature is made up of the function name plus the number and type of parameters the function expects. JavaScript functions can accept any number of parameters, and the types of parameters a function takes aren’t sp…
2016-11-29 11:00 · JavaScript
JavaScript Function Declarations vs. Function Expressions
原创转载请注明出处: http://agilestyle.iteye.com/blog/2341737 There are actually two literal forms of functions. The first is a function declaration , which begins with the function keyword and includes the name of the function immediately following it. The contents of the function are enclosed in braces, as…
2016-11-29 10:20 · JavaScript
JavaScript Primitive Wrapper Types
原创转载请注明出处: http://agilestyle.iteye.com/blog/2341689 Primitive Wrapper Types Perhaps one of the most confusing parts of JavaScript is the concept of primitive wrapper types. There are three primitive wrapper types ( String , Number , and Boolean ). These special reference types exist to make working…
2016-11-28 21:39 · JavaScript
JavaScript Primitive and Reference Types
原创转载请注明出处: http://agilestyle.iteye.com/blog/2341585 Although JavaScript has no concept of classes, it still uses two kinds of types: primitive and reference. Primitive types are stored as simple data types. Reference types are stored as objects, which are really just references to locations in memo…
2016-11-28 15:03 · JavaScript
JavaScript Object-Oriented Programming -- Inheritance
The concept most often discussed in relation to OO programming is inheritance. Many OO languages support two types of inheritance: interface inheritance, where only the method signatures are inherited, and implementation inheritance, where actual methods are inherited. Interface inheritance is not …
2012-06-14 05:23 · JavaScript
JavaScript Object-Oriented Programming -- Object Creation
The Factory Pattern The factory pattern is a well-known design pattern used in software engineering to abstract away the process of creating specific objects. function createPerson(name, age, job) { var p = new Object(); p.name = name; p.age = age; p.job = job; p.sayName = function() { alert(this.n…
2012-06-14 00:35 · JavaScript
JavaScript Functions
Functions are the core of any language, because they allow the encapsulation of statements that can be run anywhere and at any time. Functions in ECMAScript are declared using the function keywork, followed by a set of arguments and then the body of the function. The basic syntax is as follows: fun…
2012-06-11 20:07 · JavaScript
JavaScript DOM Demo
Example01 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>js_dom_demo</title> <script type="text/javascript"> function show() { document.getElementById("info").innerHTML = "<h1>Hello World</h1>"; } </script> </head> <body> <form action="" method="post"> <input type="button" value="显示" o…
2012-06-10 21:52 · JavaScript