javascript - Object with methods and own return -
I'm trying, without success, in other languages to do this, the object of which can be a default return value But its methods are as follows:
var o = {it: "MyReturn", sample string: "My string", MyMethod1: function () {}, MyMethod2: function () {},} Then, my output should be:
& gt; O & lt; "Mayerten" & gt; O Sample string & lt; "My string" & gt; O.MyMethod1 () & lt; Function () {} Is this possible? (In a way that does not use prototype, or it will conflict with my code)
It is not possible as you can cast a custom toString method and o in a string and the object will always be the same as o To function and call o like o () . Here are some options that can be turned off as javascript.
Option 1: Creating OA Function Object and Calling It. var o = function () {Return "MyReturn"; }; O Sample string = "my string"; O.MyMethod1 = Action () {}; O.MyMethod2 = function () {}; Output & gt; O () & lt; "Mayerten" & gt; O Sample string & lt; "My string" & gt; O.MyMethod1 () & lt; Function () {}
Option 2: Custom toasting method. var o = {toString: function () {} "<"> Output / Strong> & gt; String (o) & lt; "Mayerten" & gt; O Sample string & lt; "My string" & gt; O.MyMethod1 () & lt; Function () {} In this second option, replace string (o) to "+ + , O.toString () , or type-casting reason for a string.
Comments
Post a Comment