Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function with a property in javascript?

I have an object parameter and it has a property value. it is thusly defined

var parameter = {
    value : function() {
        //do stuff
    }
};

my problem is that, in some cases, value needs to have a property of its own named length

can i do that? it seems that putting this.length = foo does not work, neither does parameter.value.length = foo after the object declaration.

like image 348
griotspeak Avatar asked Mar 03 '26 12:03

griotspeak


1 Answers

The problem seems to be with the selection of the word 'length'. In JavaScript, functions are objects and can have properties. All functions already have a length property which returns the number of parameters the function is declared with. This code works:

var parameter = {
    value : function() {
        //do stuff
    }
};

parameter.value.otherLength = 3;

alert(parameter.value.otherLength);
like image 164
Ken Browning Avatar answered Mar 06 '26 02:03

Ken Browning