小编Mes*_*uvi的帖子

如何防止在 __init__() python 中创建对象

正在使用 TDD 练习 python OOP。即使给定的名称以数字开头,以下代码也会创建子类房间的类办公室的对象。我该如何预防?谢谢大家的帮助

class Room(object):

    """Create general features of a general room
    Each room has a certain capacity depending on its type(an office or a living room)
    """

    def __init__(self):
        super(Room, self).__init__()
        self.capacity = '';

class Office(Room):

    """
    Add specific features to make a room an office.
    An office has a name and a space for maximum of 4 people.
    """

    def __init__(self, rname):

        #create object if name does not start with a digit
        if not (rname[0].isdigit()):
            super(Office,self).__init__() …
Run Code Online (Sandbox Code Playgroud)

python oop init

3
推荐指数
1
解决办法
1761
查看次数

正文如何传递给此函数中的return语句

我已经遍历了某个特定的代码库,并且遇到了如下所示的函数定义:

function handleSuccess(res) {
    return (body = {}) =>
    res.status(statusCode).jsend.success({
        status: statusCode,
        success: true,
        ...body,
      })
}
Run Code Online (Sandbox Code Playgroud)

然后调用该函数,如下所示:

handleSuccess(res)({ message: 'message' });
Run Code Online (Sandbox Code Playgroud)

我似乎不明白如何将body({message:'message'})传递给上述函数的return语句。因此,对于此功能如何在Javascript中起作用,我将不胜感激。

javascript function

2
推荐指数
1
解决办法
78
查看次数

标签 统计

function ×1

init ×1

javascript ×1

oop ×1

python ×1