我有一个nodejs包,可以使用
在控制台中读取myapps.app({appId: '123'}).then(console.log); //return json result in console
我想使用可变结果来读取它:
var result = myapps.app({appId: '123'});
console.log(result);
但是它不起作用!
答案 0 :(得分:0)
由于 # Prog 120
# Rectangle & Point Classes
class Point:
def __init__(self, x, y): # makes the value required
self.__x = x
self.__y = y
@property # read only property for x
def x(self):
return self.__x
@property # read only property for y
def y(self):
return self.__y
def translate(self, dx, dy): # moves x coordinate by 'dx' amount of time and move dy
self.__x += dx
self.__y += dy
class Rectangle:
DEFAULT_WIDTH = 1 # static attributes
DEFAULT_HEIGHT = 1
rectangleCount = 0
def __init__(self, topLeft, width, height):
self.__topLeft = topLeft
# check width argument
if (width <= 0):
print("Invalid width")
self.__width = Rectangle.DEFAULT_WIDTH
else:
self.__width = width
# check height argument
if (height <= 0):
print("Invalid Height")
self.__height = Rectangle.DEFAULT_HEIGHT
else:
self.__height = height
Rectangle.rectangleCount +=1 #updates the count of rectangels created
@property
def topLeft(self):
return self.__topLeft
@topLeft.setter
def topLeft(self, newTopLeft):
self.__topLeft = newTopLeft
@property
def width(self):
return self.__width
@width.setter
def width(self, newWidth):
if (newWidth <= 0):
print("Width cannot be less than '0'. ")
else:
self.__width = newWidth
@property
def height(self):
return self.__height
@height.setter
def height(self, newHeight):
if (newHeight <= 0):
print("Height cannot be less than '0'. ")
else:
self.__height = newHeight
@property
def bottomRight(self):
return Point(self.topLeft.x + self.topLeft.y + self.height)
@property
def area(self):
return self.__width * self.__height
@property
def perimeter(self):
return self.__width *2 + self.__height *2
def translate(self, dx, dy): # moves x coordinate by 'dx' amount of time and move y
self.__topLeft.translare(dx,dy)
def main():
bill = Point(x="", y="")
will = Rectangle(topLeft="", width="", height="")
if will.width and will.height < 0:
print("Width and Height cannot be less than 0.")
will.width = will.DEFAULT_WIDTH
will.height = will.DEFAULT_HEIGHT
will.rectangleCount += 1
if __name__ == "__main__":
main()
是一个异步函数,它返回一个promise,要在同步样式代码中使用它,必须像这样使用myapps.app
语法
async/await
但是请确保此代码包含var result = await myapps.app({appId: '123'})
console.log(result)
函数。
async
或者像这样立即调用异步函数
async function() { ... }
这里有一种资源可以帮助您(async function() { ... })()
https://javascript.info/async-await