How do I start my literal object as a function like you do when you use the new Object method.
e.g. var fn = function(){ ...code...}
var func = new fn();
I'm trying to achieve this using the literal object method like:
var fn ={
key: ''
}
How do I start my literal object as a function like you do when you use the new Object method.
e.g. var fn = function(){ ...code...}
var func = new fn();
I'm trying to achieve this using the literal object method like:
var fn ={
key: ''
}
Look up "javascript constructor" :D
<script>
function construct(key, value) {
this[key]=value;
}
var foo = new construct("foo",1);
alert(foo.foo);
</script>
But that isn't the literal way of doing it, is it?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.