JavaScript types preparation for jQuery tutorial and Original From it

http://learn.jquery.com/javascript-101 This is really helpful for people to learn JavaScript. JS has nothing to do with Java actually !

And some JS data operationing methods are somehow very handy just like other programming languages such as PHP, python and etc.. You could find its awesome functionalities here http://learn.jquery.com/javascript-101/types/ .  it's more like PHP while Python also has the method " one_array.pop " or something like that. Need to figure it out from Python Doc.

JS has one_array.pop() one_array.shift() and many other methods to manipulate array object.

Here is a brief difference and usage in jQuery . Easy shot :)

// Checking the type of an arbitrary value.
 
var myValue = [ 1, 2, 3 ];
 
// Using JavaScript's typeof operator to test for primitive types:
typeof myValue === "string"; // false
typeof myValue === "number"; // false
typeof myValue === "undefined"; // false
typeof myValue === "boolean"; // false
typeof myValue === "object"; //true Coz type "array" is an object in JavaScript :)
// Using strict equality operator to check for null: myValue === null; // false // Using jQuery's methods to check for non-primitive types: jQuery.isFunction( myValue ); // false jQuery.isPlainObject( myValue ); // false jQuery.isArray( myValue ); // true. this is better than that you're just informed it's an object only

JS's basic Operators http://learn.jquery.com/javascript-101/operators/

JS's conditional codes : http://learn.jquery.com/javascript-101/conditional-code/

------------These are very useful to do some interesting convenient things.

------------e.g.              var foo = bar ? 1 : 0;           // if bar is truthy, then foo=1, or foo is assigned with 0

------------In python we have things like this. Figure it out yourself!

Objective_JS:

http://learn.jquery.com/javascript-101/this-keyword/

very interesting keyword :                  this :)

Paragragh which begins with the blow is very intelligent somehow : 

Closures can also be used to resolve issues with the this keyword, which is unique to each scope:

------From http://learn.jquery.com/javascript-101/closures/

// Using a closure to access inner and outer object instances simultaneously.
var outerObj = {
    myName: "outer",
    outerFunction: function() {
        // provide a reference to outerObj through innerFunction"s closure
        var self = this;
        var innerObj = {
            myName: "inner",
            innerFunction: function() {
                console.log( self.myName, this.myName ); // "outer inner"
            }
        };
 
        innerObj.innerFunction();
 
        console.log( this.myName ); // "outer"
    }
};
 
outerObj.outerFunction();

// Try those codes out in your JavaScript console ( firefox preferred )
原文地址:https://www.cnblogs.com/spaceship9/p/3131004.html