正在使用 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) 我已经遍历了某个特定的代码库,并且遇到了如下所示的函数定义:
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中起作用,我将不胜感激。