首页 > 代码库 > JavaScript from jQuery
JavaScript from jQuery
- http://learn.jquery.com/javascript-101/types/
- primitives
- String: “”,‘’,\
- Number: integer and floating point
- Boolean:
true
orfalse
- 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 theArray
constructor or the shorthand syntax known as array literal []. - Function
- Type Checking with jQuery
- ===
- typeof
jQuery.isFunction( myValue ); // false
jQuery.isPlainObject( myValue ); // false
jQuery.isArray( myValue ); // true
- primitives
- 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:
// Values that evaluate to false:
false
"" // An empty string.
NaN // JavaScript‘s "not-a-number" variable.
null
undefined // Be careful -- undefined can be redefined!
0 // The number zero.
Truthy:
// Everything else evaluates to true, some examples:
"0"
"any string"
[] // An empty array.
{} // An empty object.
1 // Any non-zero number.
- Conditional Variable Assignment with the Ternary Operator
- Switch Statements
- Falsy Things:
- http://learn.jquery.com/javascript-101/loops/
for ( [initialization]; [conditional]; [iteration] ) {
[loopBody]
}
while ( [conditional] ) {
[loopBody]
}
do {
[loopBody]
} 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 beforeb
, 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/
// Function declaration.
function foo() {
// Do something.
}
// Named function expression.
var foo = function() {
// Do something.
};
- // A simple function.
- // A function that returns a value.
- // A function that returns another function.
- Immediately-Invoked Function Expression (IIFE):
(function() {
var foo = "Hello world";
})();
- Functions as Arguments
- http://learn.jquery.com/javascript-101/testing-type/
- var myRegExp = /(\w+)\s(\w+)/;
if ( Object.prototype.toString.call( myArray ) === "[object Array]" ) {
// Definitely an array!
// This is widely considered as the most robust way
// to determine if a specific value is an 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()
orFunction.apply()
,this
will be set to the first argument passed to.call()
/.apply()
. If the first argument passed to.call()
/.apply()
isnull
orundefined
,this
will refer to the global object (which is thewindow
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.
- If the function is invoked using
- http://learn.jquery.com/javascript-101/scope/
- In a browser, the global scope is the
window
object
- In a browser, the global scope is the
- http://learn.jquery.com/javascript-101/closures/
- Closures are an extension of the concept of scope
- 1
- 1
- 1
- 1
- 1
- 1
JavaScript from jQuery
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。