Skip to content
Advertisement

If I changed the function name in a class, what happen to the function?

Consider the following codes

JavaScript

Now consider a few cases when executing the class as below

JavaScript

Next

JavaScript

Now if I changed the function name

JavaScript

I got

JavaScript

However,

JavaScript

I am confused

  1. denny.password = 'code:456' does not make any change to return 'code:123' in the original class, right?
  2. Has the original method password(self) been destroyed?
  3. After changing the function name, a new function code:456() pops out?

Thanks!

Advertisement

Answer

Has the original method password(self) been destroyed?

The method still exists, but it has been shadowed by another value only for the denny instance.

a new function code:456() pops out?

It’s not a function; as the error says, strings are not callable


You can change the code with a separate attribute, not by a function change

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement