Home > Web Front-end > JS Tutorial > Public and private objects in JS, namely static modifier_javascript skills

Public and private objects in JS, namely static modifier_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:56:50
Original
1517 people have browsed it
Copy code The code is as follows:

//Repackage the document object
var Console={
Write:function(msg){alert(msg);}
};
//Person object
var Person={
_name:"zzl", //static public
_age :28,
PrintInfo:function(){Console.Write("name:" Person._name ",age:" this._age);} //public method, this means Person
};

//People type (object)
var People=(function()
{
var _name="zzl";//private
var _age=28;
return { //public
PrintInfo:function(){Console.Write("name:" _name ",age:" _age);}
}
}
());

Person.PrintInfo();//Methods in the object
People.PrintInfo();//Public sub-methods in the method object
Console.Write(Person._name);//Attributes in the object
Related labels:
Statement of this Website
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
Latest Issues
php - laravel public related issues
From 1970-01-01 08:00:00
0
0
0
Don’t you need to bring public?
From 1970-01-01 08:00:00
0
0
0
public method library
From 1970-01-01 08:00:00
0
0
0
How does laravel get the public path?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template