Home  >  Article  >  Web Front-end  >  Tell me how I understand the object?

Tell me how I understand the object?

零下一度
零下一度Original
2017-06-26 10:39:352973browse

Hello everyone! Today we’re going to talk about objects.

Speaking of objects, how do we understand them? Some people may say: Well, isn’t it just the relationship between male and female friends?

Well, yes, everything is an object, there is nothing wrong with that.

But for our front-end staff, we may laugh, so what exactly is an object?

First of all, it is easy for us to understand that an object is a collection of properties and methods.

But it may not be possible for those of us who have just entered the IT industry to understand. Simply put, an object is a "thing" that has certain characteristics or functions.

For example: a person has characteristics such as nose, eyes, ears, etc., but he also has functions such as eating, eating, running, playing, etc.

Of course we can also create objects ourselves. There are many ways to create objects, but the most common ones are as follows:

1. Literal

obj = {Attribute: attribute value, attribute: function};
  obj.name=""
  obj.prototype={
      name:"zhangsan",
     age:18,
     show: function(){}
                                                                                           

# name=

 obj.age=

 obj.show=function()

3.
Construction mode:

function myFun (){

                this.name=

                this.age=

                  this.show = function(){}

         }

    var obj1 = new myFun();

var obj2 new myFun();

4. Factory method:
function myFun(){

var obj = new Object();

obj.name

                                                                                                           return obj; # 5. Prototype mode:

function myFun(){}
myFun.prototype.name

myFun.prototype.show=function(){}

obj.prototype= {
                name: "zhangsan",
                        age: 18,
                       show:function(){}
          ‐   }

‐‑‑‑   6

Mixed (Prototype +Construct)

                function myFun(){                   this.name
                      this.show=function(){}
            ‐ }
’s ’s. # myFun.prototype.info = function(){}
myFun.prototype={
show:function(){ }
    }

  
When we create the object, it will have properties and methods. We can scale the object Properties and methods, for example:




   


for(var i in obj){

                        console.log(obj[i])             }

  This is my initial understanding of the object.

The above is the detailed content of Tell me how I understand the object?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn