简体   繁体   中英

Javascript class method returning array but not assigning it to a new variable

I have the following code

var Datos = function(){
    this.salas  = ['something','other'];
}
Datos.prototype.getSalas = function(){
    return this.salas;
}

Then, If I do

var datos = new Datos();
var myArray = datos.getSalas();

Why "myArray" var is now a function and not an array?
How can I convert to an array this variable?

Works for me:

var Datos = function(){
    this.salas  = ['something','other'];
}
Datos.prototype.getSalas = function(){
    return this.salas;
}

var datos = new Datos();
var myArray = datos.getSalas();

console.log(myArray);

https://jsfiddle.net/v558tzbj/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM