It is still a consistent style in the past. For this simple method, you can directly stick the Code. At the same time, you can leave a message online. I will reply in time. Of course, the comments in the Code are also very clear, I believe everyone can also understand that, as a hard-pressed programmer, it is better to look at the code than the previous consistent style. For this simple method, you can directly stick the code, at the same time, you can also leave a message online, and I will reply in time. Of course, the comments in the Code are also very clear. I believe everyone can understand it very well. As a hard-pressed programmer, is there anything better than code? haha ~
(Function () {// in javascript, we use function to define function Shape () {var x = 1; var y = 2} // how do we instantiate an object? Using the new keyword var aShape = new Shape (); // within the class, we use var to define private variables. How can we define common variables? Function Shape2 () {this. x = 1; this. y = 2;} var bShape = new Shape2 (); // test // alert (bShape. x) // In addition to processing and defining private variables, you can also use var to define private functions // private function Shape3 () {var draw = function () {// private function} this. draw2 = function () {// common functions that can be seen from the outside} var c = new Shape3 (); c. draw2 (); // use javascript to simulate OOP programming function Shape4 (ax, ay) {var x = 0; var y = 0; var init = function () {x = ax; y = ay;} init (); this. getX = function () {return x ;}} var d = new Shape4 (2, 4); alert (d. getX (); // imitates the constructor of OOP programming, now let's write static attributes and static methods // The static methods in JS work on the class rather than the object function Person () {this. name = "YUNFENGCHENG"}; // static variable Person. age = 0; Person. showName = function (obj) {alert (obj. name)} Person. showName (new Person () // Array. each = function () {//} // simple class definition method var a ={}; var array = []; a ["name"] = "USPCAT. COM "; alert (. name )})()
/*** Map */(function () {function jMap () {// Private variable var arr ={}; // Add this. put = function (key, value) {arr [key] = value;} // query this. get = function (key) {if (arr [key]) {return arr [key]} else {return null ;}// delete this. remove = function (key) {// delete is the keyword in javascript. It is used to delete some attributes of the delete arr [key]} // traverse this. eachMap = function (fn) {for (var key in arr) {fn (key, arr [key]) }}var country = new jMap (); country. put ("01", "ZG"); country. put ("02", "HG"); country. put ("03", "MG"); country. put ("04", "TG"); // alert (country. get ("01") country. remove ("01") // alert (country. get ("01") country. eachMap (function (key, value) {document. write (key + "-->" + value +"
");})})()