My Chrome Browser has recently been updated to version 61.0.3163.79 and I noticed a strange behavior with the following Javascript code:
<!doctype html>
<html lang="fr">
<head>
<script>
var scroll = {
myFunction : function() {console.log('myFunction called');}
}
scroll.myFunction(); /* first call */
window.scroll.myFunction(); /* second call */
</script>
</head>
<body>
<button onclick="scroll.myFunction()">test1</button> <!-- third call -->
<button onclick="window.scroll.myFunction()">test2</button> <!-- fourth call -->
</body>
</html>
This code overwrites the window.scroll function (don't ask me why, that's legacy code). The result in console is the following when run and when the "test1" and "test2" buttons are clicked:
myFunction called
myFunction called
Uncaught TypeError: scroll.myFunction is not a function at HTMLButtonElement.onclick
myFunction called
In earlier Chrome version, and in MSIE 11, the function call worked properly when clicking the "test1" and "test2" buttons, resulting in the following messages in the console:
myFunction called
myFunction called
myFunction called
myFunction called
Now the questions:
- Why is Chrome Browser 61.0.3163.79 behavior different from the earlier releases and other browsers?
- Is this a bug?
- Will this behavior be adopted by future releases and other browsers?
Note that in the meantime, I changed the variable name to avoid name conflict with the browser native features.