為了證明這種方式是可以用的,我嘗試寫了個(gè)模塊: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環(huán)境里也是正常能跑的,但是為什么沒人在實(shí)際使用當(dāng)中這樣用呢?
為什么很少看到人用 __proto__ 直接來實(shí)現(xiàn)面向?qū)ο?
四季花海
2019-04-09 20:25:50