本文共 6123 字,大约阅读时间需要 20 分钟。
- http://learn.jquery.com/javascript-101/types/
- primitives
- String: “”,‘’,\
- Number: integer and floating point
- Boolean:
true
or false
- Null:null
- Undefined:undefined
- objects
- Object:object literal {:,:},unordered key and value pairs,key is formally known as a property and the value can be any valid JavaScript type, even another object. To create or access a property on an object, we use what is known as "dot notation" or "bracket notation."
- Array:ordered by the index of each item it contains.The index starts at zero and extends to however many items have been added, which is a property of the array known as the
.length
. Similar to a basic object, an array can be created with the Array
constructor or the shorthand syntax known as array literal []. - Function
- Type Checking with jQuery
- ===
- typeof
-
jQuery.isFunction( myValue );
jQuery.isPlainObject( myValue );
jQuery.isArray( myValue );
- http://learn.jquery.com/javascript-101/operators/
- Operations on Numbers & Strings
- Logical Operators
- Comparison Operators
- http://learn.jquery.com/javascript-101/conditional-code/
- Falsy Things:
-
- Conditional Variable Assignment with the Ternary Operator
- Switch Statements
- http://learn.jquery.com/javascript-101/loops/
-
for ( [initialization]; [conditional]; [iteration] ) {
-
while ( [conditional] ) {
-
} while ( [conditional] )
- Breaking and Continuing
-
- http://learn.jquery.com/javascript-101/reserved-words/
- break case catch class const continue debugger default delete do else enum export extends false finally for function if implements import in instanceof interface let new null package private protected public return static super switch this throw true try typeof var void while with yield
- http://learn.jquery.com/javascript-101/arrays/
- Arrays are zero-indexed(从0开始索引), ordered lists(保留原始的入栈顺序) of values.
- .sort(): 排序之后原来的数组已被改变,Sorts an array. It takes one parameter, which is a comparing function. If this function is not given, the array is sorted ascending.The return value of descending (for this example) is important. If the return value is less than zero, the index of
a
is before b
, and if it is greater than zero it's vice-versa. If the return value is zero, the elements' index is equal. - .forEach(): The function takes up to three arguments:
- Element – The element itself.
- Index – The index of this element in the array.
- Array – The array itself. All of these are optional
- .unshift(): Inserts an element at the first position of the array
- .shift() Removes the first element of an array.
- splice():部分元素替换, Removes a certain amount of elements and adds new ones at the given index. It takes at least three parameters: 1 myArray.splice( index, length, values, ... ); Index – The starting index. Length – The number of elements to remove. Values – The values to be inserted at the index position.
- .slice():提取从index开始到最后的部分, Extracts a part of the array and returns that part in a new array. This method takes one parameter, which is the starting index:
- reverse():倒序之后原来的数组已被改变, the elements of the array are in reverse order after calling this method
- .push(): is a function that adds an element on the end of the array and expands the array respectively.
- .pop() : removes the last element of an array. It is the opposite method of .push()
.join()
creates a string representation of an array by joining all of its elements using a separator string - Concatenate two or more arrays with .concat():
.length
property is used to determine the amount of items in an array
- http://learn.jquery.com/javascript-101/objects/
- Objects contain one or more key-value pairs. The key portion can be any string. The value portion can be any type of value: a number, a string, an array, a function, or even another object. When one of these values is a function, it’s called a method of the object. Otherwise, they are called properties.
- http://learn.jquery.com/javascript-101/functions/
-
-
- // A simple function.
- // A function that returns a value.
- // A function that returns another function.
- Immediately-Invoked Function Expression (IIFE):
- Functions as Arguments
- http://learn.jquery.com/javascript-101/testing-type/
- var myRegExp = /(\w+)\s(\w+)/;
-
if ( Object.prototype.toString.call( myArray ) === "[object Array]" ) {
- http://learn.jquery.com/javascript-101/this-keyword/
this
is a special keyword that is used in methods to refer to the object on which a method is being invoked -
- If the function is invoked using
Function.call()
or Function.apply()
, this
will be set to the first argument passed to .call()
/.apply()
. If the first argument passed to .call()
/.apply()
is null
or undefined
, this
will refer to the global object (which is the window
object in web browsers). - If the function being invoked was created using
Function.bind()
, this
will be the first argument that was passed to .bind()
at the time the function was created. - If the function is being invoked as a method of an object,
this
will refer to that object. - Otherwise, the function is being invoked as a standalone function not attached to any object, and
this
will refer to the global object.
- http://learn.jquery.com/javascript-101/scope/
- In a browser, the global scope is the
window
object
- http://learn.jquery.com/javascript-101/closures/
- Closures are an extension of the concept of scope
- for(var i=0;i<5;i++){console.log(i+" : before");setTimeout(function(){console.log(i + " "+new Date());},i*1000);console.log(i+" : after")}
转载于:https://www.cnblogs.com/dmdj/p/4149297.html