// Constructor
Var myConstructor = function (msg ){
This. msg = msg;
// Private attributes
Var separator = '-';
Var that = this;
// Private Method
Function alertMsg (){
Alert (that. msg );
}
AlertMsg ();
// Privileged method
This. appendToMsg = function (str ){
This. msg + = separator + str;
AlertMsg ();
}
}
// Public Method
MyConstructor. prototype. clearMsg = function (str) {this. msg = '';};
// Static attributes
MyConstructor. youName = 'bolen ';
// Static method
MyConstructor. sayName = function (){
Alert (this. youName );
}
Var a = new myConstructor ("hi ");
A. appendToMsg ("Ryan ");
MyConstructor. sayName ();
// The Object literal syntax automatically creates an instance of the Object, but it cannot be instantiated again using the new keyword.
// If you want to use the same object literal syntax to construct a constructor with a public method, you still need
// Start the Function object of the constructor