This article mainly introduces the JavaScript changes the original object valueof method, involves JavaScript uses the custom valueof function replaces the original object The valueof the technique, has certain reference value, the need friend may refer to under
The example in this article describes how JavaScript changes the original object valueof. Share to everyone for your reference. The specific analysis is as follows:
The objects in JS contain the valueof method, we can replace the original object by the custom valueof function valueof
?
1 2 3 4 5 6 7 8 9 |
function foo () {this.valueof = function () {return ' is ' I value ';}} var bar = new Foo (); Print (bar); Prints:this is my value print (bar = = ' This was my value ')//prints:true Print (bar = = ' This is my value ')//Prin Ts:false |
I hope this article will help you with your JavaScript programming.