链式调用原理实现

1 链式调用(jq),用python实现链式调用 (对象hello.world.add)

class ChainMethods(object):
def init(self, name):
self.name = name

@property
def hello(self):
    print(f'你好{self.name}的')
    return self

def world(self):
    print("世界")
    return self

world = property(world)

def add(self):
    print("你吃了吗")
    return self

c = ChainMethods('egon')
c.hello.world.add()

posted @ 2020-07-07 16:42  给你加马桶唱疏通  阅读(138)  评论(0编辑  收藏  举报