Some JavaScript Quiz

ax = a = {}, in-depth understanding assignment expression

{X = O var:. 1}; 
var A = O; 

AX = A = {name: 100}; 

the console.log (AX); // undefined 
the console.log (OX); // {name:} 100 

// a = {name = ax: 100}; 
// equivalent = ax (a = {name: 100} ) ; 
// first calculates ax reference, then calculates (a = {name: 100} ) return value

Shorthand if statement

var condition = true, numb = 0;
if(condition) {
    alert('rain-man')
}
if(condition) {
    numb = 1 + 2;
}

Equivalent to

var condition = true, numb = 0;
condition && alert('rain-man');
condition && (numb = 1 + 2);

&& and || are calculated values

(true && 222);	    // 222
!!(true && 222);    // true
(false && 222 );    // false
 
    
(false || 222);     // 222
!!(false || 222);   // true

!! variable returns a boolean value and the original value equal

Object of the construction

function Object() { [native code] }
Object.prototype = {
	constructor: function Object() { [native code] },
	hasOwnProperty: function hasOwnProperty() { [native code] },
	isPrototypeOf: function isPrototypeOf() { [native code] },
	propertyIsEnumerable: function propertyIsEnumerable() { [native code] },
	toLocaleString: function toLocaleString() { [native code] },
	toString: function toString() { [native code] },
	valueOf: function valueOf() { [native code] }
};

Object.prototype.constructor === Object;    // true

prototype some of the details

var A = function(){
    this.name = 'rain-man';
};
A.prototype = {
    name : 'cnblogs'
};
var o = new A();
console.log(o.name);    // 'rain-man'
function B = var () {}; 
B.prototype = { 
    name: 'obj-B' 
}; 

var new new B = O (); 
o.name = 'obj-C'; 
Delete o.name; 
the console.log ( o.name); // 'obj-B ', storm drain prototype chain

Create an object and keep the prototype chain

O function = var (obj) { 
    function T () {} 
    T.prototype = obj; 
    return new new T (); 
}; 

var obj = {name: 'obj', Age: 0}, 
    OBJ1 = O (obj), 
    O = obj2 (OBJ1); 

// change the prototype of a chain, the chain will change all the prototype 
obj.name = 'the superclass';     
the console.log (obj1.name); // 'the superclass' 
the console.log (obj2.name ); // 'the superclass' 

// each layer may be processed individually 
obj1.name = 100; 
the console.log (obj1.name); 100 // 
Delete obj1.name; // storm drain prototype chain 
console.log (obj1. name); // 'superclass'

Reproduced in: https: //www.cnblogs.com/rainman/archive/2010/10/16/1853222.html

Guess you like

Origin blog.csdn.net/weixin_34353714/article/details/93561269