Skip to content

Instantly share code, notes, and snippets.

@Alex-xd
Created September 10, 2016 02:51
Show Gist options
  • Save Alex-xd/2107751df3b8031ea718ad4849301cef to your computer and use it in GitHub Desktop.
Save Alex-xd/2107751df3b8031ea718ad4849301cef to your computer and use it in GitHub Desktop.
一段代码解释JavaScript面向对象
作者:颜海镜
链接:https://zhuanlan.zhihu.com/p/22388052
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
(function(){
//私有静态成员
var user = "";
//私有静态方法
function privateStaticMethod(){
}
Box = function(value){
//私有成员
var privateStaticUser = value;
//这个是私有方法
function privateMethod(){
}
//公有方法,因为能访问私有成员,也可以说是特权函数,也可以说是实例方法
this.getUser = function(){
return user;
};
//公有成员
this.user = 1;
};
//公有共享访问
Box.prototype.sharedMethod = function () {};
//公有共享属性
Box.prototype.sharedProperty = function () {};
//公有静态方法
Box.staticMethod = function(){};
//公有静态成员
Box.staticProperty = 1;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment