Put on a section of colleagues write code, value of the memorial
<script type= "Text/javascript" >//Create a box class functionBox (option) {varSelf = This; var_option ={height:12, Width:12 }; //Merging Parameter objects: Remember to quote Jquery.js$.extend (_option, option); This. Height =_option.height; This. width =_option.height; //Binding Event List var_events = {}; //Create a method with a callback function This. Push =function(option, callback) {if(Option.height > This. Height) {Console.error ("Over height", This); return; } if(Option.width > This. Width) {Console.error ("Over width", This); return; } //determine if there is a callback function if(CallbackinstanceofFunction)//call the callback function and give it a value (parameter: _option)Callback.call ( This, _option); } //Binding Events This. on =function(name, event) {if(Name = =NULL|| !name)return NULL; if(! (EventinstanceofFunction)) if(Self[name]instanceofFunction) { returnSelf[name] (); } if(EventinstanceofFunction) _events[name]= Self[name] =function() {event.apply ( This); return This; } } //Unbind Event This. Unbind =function(name) {DeleteSelf[name]; Delete_events[name]; //Chained Expressions return This; } } //Create a Box1 object varBox1 =NewBox (); //Create a Box2 object varBox2 =NewBox (); //Calling MethodsBox1.push ({height:12, Width:12//callback function},function(option) {Console.log ("The push callback function has been called:", option); }); //dynamically binding events to ObjectsBox1.on ("click",function() { This. width + = 10; Console.log (The "width increment 10,click event is called ...", This. width); }); Box1.on ("Heihei",function() {Console.log ("The Heihei event was called ...", This. width); }); //Event Normal CallBox1.click (); //chained expression invocation methodBox1.on ("click"). Click (). Heihei (). On ("Heihei"); //Print the width of the box1Console.log (box1.width); //Print the width of the Box2Console.log (box2.width); //Unbind EventBox1.unbind ("Heihei"); //Test ReleaseBox1.heihei ();</script>
JS Object-oriented code