A little understanding of JavaScript objects

Source: Internet
Author: User

<script type= "Text/javascript" >/*js object: The responsibility of the object is to invoke the property and invoke the method *///1. Three ways to create an object var obj = {}; Commonly used and does not waste space var obj = new Object ();//var obj = Object.create ();/* The Third way to test the time there is a problem, under Baidu, found Object.create () method to create an object that has a specified prototype and several specified properties.  Parameter: Prototype required. The object to use as a prototype. can be null. Descriptors is optional. A JavaScript object that contains one or more property descriptors. *///2. The presence of a key-value pair: jsonvar person = {username: "Xiaobai"}//object's additions and deletions person.age = "a";p erson.address = "Nanjing"; Console.log ( person.username+ "= = =" +person.age+ "= = =" +person.address);//Modified value Person.username = "Xiaoking";p erson.age = 20;// Remove value Delete person.age;//do not understand the alert or use Console//3.json object var data = {username: "Poseidon"}/* the value there are two first: object. Property facilitates invocation of properties The second type: Object ["attribute name"] Convenient value */console.log (data.username+ "= = =" +data["username"]);/* Single attribute can be used this way, but multi-attribute JSON object is not the same */var params = {" User.Name ":" "," User.age ":" "}params[" User.Name "]//value cannot use point Params.user.name, will error console[" log "] (" console is also object "); var Console = {log:function (msg) {}}//4. Write a jquery framework function $ (ID) {var obj = {css:function () {}html:function () {}}} (function () {var window.$ = document;}) (window); var $ = function (ID) {if (Id.indexof ("#")) id = id.replace ("#", "" "), var dom = document.getElementById (ID); return { Css:function (Key,value) {if (typeof key = = = "Object") {}else{if (typeof key = = = "Number") value = value + "px";d om["style"] [ Key] = value;}}}} 5. You can learn the latest DOM knowledge for (Var key in document) {Console.log (Document[key]) without buying a book of any DOM object;} </script>

  

A little understanding of JavaScript 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.