為了證明這種方式是可以用的,我嘗試寫了個模塊:https://github.com/jiyinyiyong/proto-scopehuman=proto.asinit:->@name='humanrace'give_name:(@name)->introduce:->console.log"thisis#{@name}"tom=human.new()tom.introduce()#=>"thisishumanrace"man=human.asspeak:->print'speaksby',@namedan=man.new()dan.give_name'Dan'dan.introduce()#=>"thisisDan"dan.speak()#=>"speaksbyDan"從功能上說,proto是可行的,在Node環境里也是正常能跑的,但是為什么沒人在實際使用當中這樣用呢?
為什么很少看到人用 __proto__ 直接來實現面向對象?
Smart貓小萌
2019-04-08 11:19:12