如何用JS动态创建一个function并且能够执行
展开全部
不能吧,只能给function加属性
或者弄面向对象明基搜
var Dog = function (name, age) {
this.name = name;
this.age = age;
this.say = function () {
console.log(this.name + "激历==>>汪汪汪"锋斗);
}
};
var dog1 = new Dog("白",12);
var dog2 = new Dog("黑",121);
dog1.say();
dog2.say();
或者弄面向对象明基搜
var Dog = function (name, age) {
this.name = name;
this.age = age;
this.say = function () {
console.log(this.name + "激历==>>汪汪汪"锋斗);
}
};
var dog1 = new Dog("白",12);
var dog2 = new Dog("黑",121);
dog1.say();
dog2.say();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询