A trustworthy object is one that does not have a public property and its methods do not refer to this object. A secure object function follows a pattern similar to a parasitic constructor, but has two different points: one is that the instance method of the newly created object does not reference this, and the constructor is not invoked with the new operator.
When browsing blogs recently, I found that a lot of people seem to understand the sound constructor, and one of the features of this function, and the other constructors mentioned in the JavaScript Advanced program, is that private quantization can be realized by using JS scope.
function Process (NAMEF) {
var o = new Object ();
var name = namef;//1
o.sayname = function () {
alert (name);//2
};
return o;
}
var friend = Process (' Nick ');
Friend.sayname (); "Nick"
Console.log (friend.name);//UNDEFINED//3
Note: (3 points below)
1. In a secure constructor, a variable cannot be suspended to 2 of the object being returned
. UseThis 3 when you are working with custom functions in a secure constructor. Use
a secure constructor outside of a function without new.