JS (i) Basic knowledge and objects

Source: Internet
Author: User

First, Introduction

In JS, everything is the object. strings, arrays, functions, and so on are all objects.

Second, the common JS function

/** * Display object's property method one * @returns */function myFunction1 () {person = {firstname: "David", LastName: "Smith", Age:30,sex: ' Male '};// Each is a new object, the property value can not be fixed//person2 ={...}; Printinfo (person);} /** * Display object's Properties method two */function MyFunction2 () {person = new Object ();p erson.firstname = "David";p erson.lastname = "Smith"; Person.age = 30;person.sex = ' Male ';p rintinfo (person);} /** * constructor * @returns */function person (firstname,lastname,age,sex) {this.firstname = Firstname;this.lastname= lastname; This.age = Age;this.sex = Sex;this.test = test2;//This must not be less function test2 () {document.write ("Call the person's Test ()");//alert ( "Call the person's Test ()");}} /** * Display object's property method three */function MyFunction3 () {var p = new Person ("David", "Smith", 30, ' male ');//p.test ();////printinfo (P);} /** * Traverse the property of the Person object */function Traversalperson () {//If you want to traverse this, you cannot use the constructor to create the object, var p = {firstname: "David", LastName: "Smith" , Age:30,sex: ' Male '};var str= ", var x;for (x in P) {str + = p[x]+", ";//js with" + = ", php with". = "}//document.write (str); document.getElementById ("Div1"). Innerhtml=str;} /******************** General Method ******************************//** * Output character information */function Printinfo (person) {document.getElementById ("Div1"). Innerhtml= "Name:" + person.firstname + "+ Person.lastname +", Age: "+person.age+", Gender: "+ person.sex;}


JS (i) Basic knowledge and objects

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.