OOP in JS

JavaScript is different from others object-oriented language like c++,java.It's not based on the concept of class,but it uses to a concept named prototype.

The public,private and static of oop concepts can be  implemented by prototype in javascript.The following are the methods to implement these concepts:

private variables are declared with 'var' key word inside the object,and can only be accessed by private functions and privileged methods.

private functions are declared inline inside object's constructor(or alternatively may be defined via var functionName=function(){...}) and may be called by privileged methods(include the object's constructor).

privileged methods are declared with this.methodName=function(){...} and may invoked by code external to the object.

public properties are declared with this.variableName and may be read/writen from outside the object.

public methods are defined by Classname.prototype.methodName = function(){...} and may be called from outside the object.

prototype properties are defined by Classname.prototype.propertyName= someValue

static properties are defined by Classname.propertyName = someValue




an usefull link

你可能感兴趣的:(JavaScript,C++,c,prototype,oop)