See an article on JavaScript single case HTTP://BLOG.CRAZYCODER.CC/POST/13
Some thoughts on javascript new operations:
Scenario 1:
function Test1 () {
return {name: ' Test1 '};
};
Result of new test1: {name: ' Test1 '}
Scenario 2:
function Test2 () {
};
Test2.prototype={name: ' Test2 '};
Result of new test2: {name: ' Test2 '}
Scenario 3:
function Test3 () {
return {name: ' Test3-1 '};
};
Test3.prototype={name: ' Test3-2 '};
Result of new test3: {name: ' Test3-1 '}
Scenario 4:
function Test4 () {
Return ' test4 ';
};
Result of new test4: {}
Scenario 5:
function Test5 () {
return [];
};
Results of new TEST5: [];
Scenario 6:
function Test6 () {
return function () {return ' Test6 '};
};
New Test6 Result: function () {return ' Test6 '};
Conclusion:
Unlike Java, JavaScript's new operation has a return value, and the return value can be an object, an array, a function, or, if the return value type does not meet the requirements, a shallow clone of the prototype is returned, otherwise the return value object is returned.
Questions:
In the original
Constructor Pointer instance. =Singleton;
This line of removal seems to be correct ...
Thinking of the new operation of JavaScript