Adding a Method to an Existing Object Instance

后端 未结 16 2967
夕颜
夕颜 2020-11-21 05:45

I\'ve read that it is possible to add a method to an existing object (i.e., not in the class definition) in Python.

I understand that it\'s not always good to do so

16条回答
  •  长情又很酷
    2020-11-21 05:51

    Since this question asked for non-Python versions, here's JavaScript:

    a.methodname = function () { console.log("Yay, a new method!") }
    

提交回复
热议问题