Javascript-object type

Source: Internet
Author: User

Creation of Object

var obj1 = new Object ();  constructor method to create var obj2 = {};  Object Literal method Creation

Differences created by using constructors

var obj1 = new Object (+ 1); alert (obj1);  101var obj1 = new Object (+), obj1 + = 100;alert (typeof obj1);  "Number" function num () {return 100;} var obj1 = new Object (num); alert (obj1 ());  100alert (typeof obj1);  "Function"

Assignment of Object

var obj1 = new Object (); obj1.name = "Jack"; obj1.sayname = function () {    return This.name;};o bj1["Year of age"] = "1992";  Associative array assignment alert (obj1["Year of age"]);  "1992" var obj2 = {  //dynamic assignment can also be used for literal    name: "Eson",    sayname:function () {        return this.name;    },
     "Year of Age": "1992"};alert (obj2[, "Year of age"]);  "1992 25"

Anonymous objects

function DisplayInfo (obj) {    return obj.name + "" + obj.age;} Alert (DisplayInfo ({    name: "Nopi",    age:25}));  "Nopi 25"

Enumerating the properties of an object

var obj2 = {    name: "Jack",    age:25};with (obj2) {    var str = "Name:" + name + "\ n";    str + = "Age:" + Ages;} alert (str);  "Name: Jack Age:" var obj2 = {    name: "Jack",    Age:25};for (var p in obj2) {    alert (p);  "Name" "Age  "}

Javascript-object type

Related Article

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.