1, use strict mode, add code specification
' Use strict '
This is a good habit to avoid some hidden errors in your code. Strict mode is used by default in ES6
2, JS ES5 Two ways to declare the method
(function () { ' use strict '; // A function expression that assigns a method to a variable, which must be called after the declaration. // recommended ways to use the website var function () { }; // is a function declaration, it will be promoted to the top of the entire JS, can be called directly at any time function fun2 () { } }) ();
3, JS ES5 object-oriented notation
(function () { ' Use strict '; varOBJ =function () { //Way One This. fun1 =function() {Console.log ("Test1"); } } //Mode twoObj.prototype.fun2 =function() {Console.log ("Test2"); }; varobj =NewOBJ (); Obj.fun1 (); Obj.fun2 (); })();
4, JS ES6 object-oriented notation
class Obj { fun1 () { console.log (' fun1 ');} } var New Obj (); obj.fun1 ();
JavaScript ES5 notation