在定义之后将属性添加到匿名JavaScript类型?
问题描述:
我知道在JavaScript中你可以为现有类型添加新属性(比如Date),但是在定义匿名类型之后是否可以添加新属性?
I know that in JavaScript you can add new properties to an existing type (like Date), but is it possible to add new properties to an anonymous type after it's been defined?
例如,假设我有以下脚本:
For example, say I have the following script:
var employee = {
'Name': 'Scott',
'Age': 32,
'JavaScriptNewbie': true
};
稍后在我的脚本中我想为这个员工对象添加一个新属性(比如,Salary) 。这可能吗?
Later on in my script I want to add a new property to this employee object (say, Salary). Is that possible?
TIA!
答
employee.Salary = value;