So I have a Javascript function i.e
var object = function(){
function sayHello(){
console.log("Hello");
}
}
Is there a way to redefine the object.sayHello method later on in my code such that instead it prints "Bonjour"?
So I have a Javascript function i.e
var object = function(){
function sayHello(){
console.log("Hello");
}
}
Is there a way to redefine the object.sayHello method later on in my code such that instead it prints "Bonjour"?
You can override functions in Javascript. All you have to do is re-declare it later on.
var hello = function(){
alert("Hello");
}
function changeFunction(){
hello = function(){
alert("Goodbye");
}
}
<button onclick="hello()">Run Function</button>
<button onclick="changeFunction()">Change function</button>
js
var input = document.getElementById('input').value;
var object = function(){
function sayHello(input){
console.log(input);
}
}
and html
<input type="text" name="input" id="input" placeholder="enter greetings">