1 year ago

Javascript class constructor fail

Posted 1 year ago by mironmg

Hi guys

I have a js class called Property that I am using in my vue templates and a constructor Basically when I load a page, I make an ajax request to server, get the info for that model, assign it to a js object that I am using aftewards in my webapp.

So this object has a constructor class. Everything works fine except for one field which is listing_type This value assigns false, always. If I force assign it to a random string it works. If I console.log the variable it works. but when I assign the variable it does not. any ideas? Example below

class Property {
    constructor(db_property) {
        for(let field in db_property){
            this[field] = db_property[field];
        //everything works fine but when field == listing_type it just assigns false instead of the string

LE. Nevermind, I found the issue right after I posted. it was me using a '=' instead of a '==' later in that page. Unfortunately I can't delete the thread.

Please sign in or create an account to participate in this conversation.