在浏览器中,我尝试评估以下代码段:
window = 1; console.log(window)
控制台中打印的值仍然是原始窗口对象,而不是数字1
。
有没有人知道为什么window
对象无法重新分配?这是Javascript语言的一个特性吗?我可以让自己的对象也不像窗口对象那样可写吗?
答案 0 :(得分:2)
它不能被覆盖,因为它被定义为不可写。
这是JS的一个特性(尽管var example = {};
Object.defineProperty(example, "foo", {
value: "Hello",
writable: false
});
document.body.appendChild(document.createTextNode(example.foo));
example.foo = "World";
document.body.appendChild(document.createTextNode(example.foo));
对象可能在较低级别实现)。
from time import strftime
import urllib2, boto3
timekey = strftime("%Y-%m-%d %H:%M:%S")
time = strftime("%H:%M:%S")
response = urllib2.urlopen('http://open-stocks.com/api/get-data-' + time + '.json')
data = response.read()
s3 = boto3.resource('s3')
s3.Bucket('my-stocks-bucket').put_object(Key=timekey, Body=data)
答案 1 :(得分:1)
frames
,self
和Window
IDL属性必须全部返回WindowProxy
对象的浏览上下文的window
对象。
“必须”这里暗示无论你做什么,对if (x == 1)
{
Area.Square(i);
}
else if (x == 2)
{
Area.Rectangle(j, i);
}
else if (x == 3)
{
Area.Triangle(j, i);
}
else if (x == 4)
{
Area.Circle(i);
}
else
{
Console.WriteLine("That is an invalid choice");
}
的每个请求都会产生WindowProxy对象。