Amyth
Amyth

Reputation: 32949

how to setattribute of a javascript object dynamically

I am looking to set an attribute of an object dynamically. Look at the example below.

function testFunc(type, scope){
    this.scope = scope;
    this.scope.setAttribute(type, true);
    this.doSome = function(){return //Something;}
}

but I realized that setAttribute method is only available for DOM elements. Is there a way i can set an attribute dynamically to a js object ?

Upvotes: 0

Views: 4958

Answers (1)

mpm
mpm

Reputation: 20155

function testFunc(type, scope){
    this.scope = scope;
    this.scope[type]= true;
    this.doSome = function(){return //Something;}
}

should do the trick.

Upvotes: 2

Related Questions