jquery Learning Notes

Source: Internet
Author: User

1. Function: Produces an object (feels a bit like the class in Java)The example is as follows:/*** The function is an object that is generated by function */function person () {}alert (person.constructor); Person.a = 5;//Adds a property to the person object with a value of 5 function Student () {} person.b = student;//Adds a property of B to the person object, and a value of Student for the object var JSON = {aa: ' AA '}; PERSON.C = json;//gives the person object another attribute of the Heaven boundary is C, and the value is JSON object alert (PERSON.C.AA);2, the role of Eval/*** adds multiple JSON objects to the window */eval ("window."). +temp.join (".") + "={}");//Add multiple function to the window eval ("window.") +temp.join (".") + "=function () {}");3, prototype, equivalent to the attributes in JavaExample: function person () {}alert (person.prototype); The person is a function object with a default property of prototype={}, which does not exist in the JSON object PERSON.PROTOTYPE.AA = 5;//can also be written like thisperson.prottype[' AA '] = 5;PERSON.PROTOTYPE.BB = function () {alert ("BB");}  var p = new person (); alert (P.AA); /*** simulates a class, creates an object, sets the property, and outputs */function Student () {} Student.prototype.setId = function (id) {this.id = ID;} Student.prototype.setName = function (name) {this.name = name;} Student.prototype.getId = function () {return this.id;} Student.prototype.getName = function () {return this.name;} var s = new Student (); S.setid (4); S.setname ("King of the two lepers"); Alert ( S.getid ()); alert (S.getname ()); var s = new Student (); S.setid (4); S.setname ("King of the two lepers"); Alert (S.getid ()); alert (S.getname ());   S.BB = 5;alert (S.BB); var ss = new Student (); Alert ("---------" +ss.bb); Description: Although s.bb = 5; The equivalent of a new BB property for the S object, but the primary student does not add the BB attribute, so the "undined" is displayed4, inheritance-the basic form. Through the prototype of the objectExample function Student () {}student.prototype.setname = function (name) {this.name = name;} Student.prototype.getName = function () {return this.name;} function Superstudent () {}superstudent.prototype = Student.prototype;OrSuperstudent.prototype = new Student ();var superstudent = new Superstudent (); Superstudent.setname ("BB"); Alert (Superstudent.getname ());4, inheritance--the form of encapsulation/*** defines a function inside the extend function that dynamically adds each key,value value of the JSON object passed in to the prototype of the inner function * @param {Object} json*/namespace (" Com.itheima12 "); com.itheima12.extend = function (JSON) {/*** declares a function */function F () {}/*** iterates through each key,value value in the JSON object, Assign each value of Key,value to F.prototype*/for (var i in JSON) {f.prototype[i] = json[i];} Return f;//f is an object}//var person = Extend ({//AA: ' AA ',//bb: ' BB '//}); var = com.itheima12.extend ({aa: ' AA ', bb: ' BB '} var p = new person (); alert (P.AA);Closed PackageA function defined inside a function that is externally enclosing a usage scenario: an example of an inherited encapsulated anonymous function: (function (window) {function person () {return {setname:setname,getname: GetName};} /*** Public Function * @param {Object} name*/function setName (name) {this.name = name;} function GetName () {return this.name;} /*** Private Function */function aaa () {}function bbb () {}//Adds a property dynamically to the Window object personwindow.person = person;}) (window); var person = window. Person (); Person.setname ("AAA"); Alert (Person.getname ());

JQuery Learning Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.