【发布时间】:2019-10-20 03:12:07
【问题描述】:
假设我们有一个函数,里面有一个对象等等:
function myFunc() {
var obj = {
"one" : "1",
"two" : "2"
};
// And more code is down here but our main focus is in the obj object.
};
现在考虑另一个专门为 myFunc() 设计的函数,它可以在 myFunc() 中添加或删除对象 obj 的属性。例如,考虑到函数 manip() 是可以在函数 myFunc() 中缩小 obj 对象的特殊函数:
manip("add", {
"three" : "3"
};
/* Now the obj object inside myFunc() becomes :
var obj = {
"one" : "1",
"two" : "2",
"three" : "3"
}
再次:
manip("remove", "one three");
/* Now the obj object inside myFunc() becomes :
var obj = {
"two" : "2"
}
那么,这可能吗?可以制作manip()函数吗?
【问题讨论】:
-
完全不清楚你在问什么。
-
不清楚的地方请告诉我
-
您可以在运行时读取、编辑和评估用户代码,是的。
-
您不能从另一个函数更改一个函数内部所做的事情。你应该描述你想做什么,因为你发布的内容根本没有意义。
-
我只是想知道它是否可能
标签: javascript object