JavaScript Bind Method
JavaScript Bind Method,! The Bind Method is basically a call function or method with the Variable under this value being set explicitly inside the method. Simple Saying the bind() method will enable the Value/ variable specified using the this key word inside the method to be accessed when the method is being invoked.
Refer the Sample Code Below
<script type="text/javascript"> //This is a New Array var userName; var printName; var printNames; function outArray() { // first accessing Method via bind function printName = userName.getNameNow.bind(userName); // Accessing via dot name. printNames = userName.name; document.getElementById("outputElement").innerHTML = printName(); document.getElementById("outputElements").innerHTML = printNames; } function insertData(classObj){ classObj = document.getElementById("insertName").value; userName = { name: "", getNameNow :function(){ return this.name; } }; userName.name = classObj; } </script> </head> <body> <h2>Click the below button to see what is inside our Array Element</h2> <P> <input type="button" value="Check what is inside" id="" onclick="outArray();"/></P> <p id="outputElement"></p> <p id="outputElements"></p> <P style="color:blue;"><strong>Enter an Element that you want to save into the internal Object Class:</strong><input type="text" style= "text-align:center; margin-left: 10px;"id="insertName" name="element" placeholder="Save Element into Object" > <p><input type="button" style="text-align:center; margin-left: 10px;" value="Save" id=""onclick="insertData(this.classObj );"/></P>
Check out Object in JavaScript Here
Leave a Reply