JavaScript Object definitions and operations

Source: Internet
Author: User

There are three ways to define JS objects
There are three ways of defining JS methods
function fn () {}
var fun = function () {}
var fun = new function () {}
//******** *********************************//
<! DOCTYPE html>//var a = "123"; //function fn () { //alert (a); //var ab = "4321"; // } //fn (); //new Object (); //create a normal object varA = 3, B = 9; varobj = { //Defining PropertiesName: "123", Fun1:function () { } } //obj.name = "haha";OBJ.FUN1 =function(A, b) {alert ("Iosdjfoij"); returnA +b; } //Delete obj.name; //alert (obj.name); //Alert (Obj.fun1 (A, b)); //Constructor declaration, which can be understood as a class in Java, a class is an object functionObj () {//In the constructor mode in Java This. Name = "Hahaa"; This. fun1 =function(A, b) {returnA +b; } } //to use the constructor, you must instantiate the constructor, create the object varOBJJ =NewOBJ (); Objj.name= "HelloWorld"; //Objj.fun1 (A, b) { //return a+b; //} //Modify object, Format: Small object. Method Small object. Properties //Add New Object //format: Small object. New method =Objj.func23 =function () { return("No. Third"); } alert (Objj.name); Alert (objj.func23 ()); //Alert (Objj.fun1 (A, b)); //crud Operations on objects</script>

JavaScript Object definitions and operations

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.