Some knowledge fragments of JavaScript (1)
I plan to raise the Javascript usage level from child to elementary school, and will keep some knowledge points in the near future. Javascript reference mechanism: a reference is established as long as an object is assigned a value to another object. Once a reference is created, objects share a space. You can refer to the following code: copy the code var stooge = {nickname: "Maria"} var x = stooge; console. log (stooge. nickname); // Maria x. nickname = 'curly '; x. realname = "Thomas" console. log (stooge. realname); // The realname attribute added by Thomas by x. Var nick = stooge. nickname; console. log (nick); // apparently the Curly console. log (stooge. nickname); // It is overwritten. There is no strong class concept in Curly copy code java, and there is no distinction between class and instance. The usage of the new Keyword is similar to that of java. It is also used to create a new object. However, objects in js cannot be created only by using the new method. For example, objects of the function type can be created by explicitly declaring, assigning values to variables, or calling the Function constructor. Javascript Prototype: each object has a prototype and inherits attributes from it. All objects inherit the attributes of Object. prototype. When creating a new object, you can select an object as prototype to directly inherit its attributes. Here is a new memory space, rather than reference. Through the following code, we can easily let an Object inherit the prototype of another Object to copy the Code if (typeof Object. inherit! = 'Function') {Object. inherit = function (obj) {var fun = function () {}; fun. prototype = obj; return new fun () ;};} var lucasliu = {job: "tester", holobby: "reading"} var a = Object. inherit (lucasliu); // "inherit", in fact, all properties are copied to the console. log (. job); // tester inherits from lucasliua. job = 'Doctor'; console. log (. job); // The doctor value is overwritten as the doctorconsole. log (lucasliu. job); // tester, lucasliu is not affected. newskill = "play piano"; console. log (A. newskill); // play piano a and prototype get new skills.