Existe-t-il un raccourci dans MooTools pour indiquer si un objet est un objet ou un tableau?MooTools: Comment savoir si l'objet est un tableau?
Répondre
MooTools a un type de $(), où l'on passe dans un objet.
var myString = 'hello';
$type(myString);
Vous pouvez trouver plus d'informations à http://mootools.net/docs/core#type
ne suis pas sûr MooTools, mais vous pouvez vérifier avec Javascript:
var someObject = [];
console.log(someObject instanceof Array) // logs true
Mais depuis un tableau est un objet, il vous faudrait vérifier si elle est un tableau avant de vérifier pour objet. Mais en utilisant la méthode $type
est probablement plus facile.
Modifier:
Mootools fournit une fonction de type $ qui donne le type d'un objet:
Tests couru:
console.log($type("hello"));
console.log($type(new Object()));
console.log($type([1, 2, 3]));
Sortie:
string
object
array
Essayez avant de l'acheter au http://mootools.net/shell/
trouvé les informations de cet article - http://javascript-reference.info/useful-utility-functions-in-mootools.htm
Le chèque 'de instanceof' retourne' false' pour un tableau cela vient d'une autre fenêtre ou d'un autre cadre. –
Vous pouvez le faire avec JavaScript natif:
Object.prototype.toString.apply(value) === '[object Array]'
- 1. Comment savoir qu'un paramètre est un tableau?
- 2. Comment savoir si un ordinateur est redémarré
- 3. Comment savoir si un utilisateur est connecté?
- 4. La meilleure façon de savoir si un objet DOM est visible ou non, en utilisant mootools
- 5. Comment savoir si un fichier est un lien?
- 6. comment savoir si une forme est praticable
- 7. Comment savoir si UITableViewCell est sélectionné?
- 8. Comment savoir si NSUserDefaults est déjà enregistré?
- 9. Comment savoir si une session est active?
- 10. Comment savoir si Oracle Streams est installé?
- 11. Comment savoir si l'applet ou l'application est
- 12. Comment puis-je savoir si une valeur est dans un tableau en C?
- 13. Comment savoir si l'objet raphael est caché?
- 14. Comment savoir si dll RAPI est existant
- 15. Comment savoir si une fonction est terminée?
- 16. Vérifiez si une variable est un tableau
- 17. Comment savoir si un PropertyInfo est une collection
- 18. Comment savoir si un hachage Perl est multidimensionnel?
- 19. Comment savoir si le PC est connecté à un réseau?
- 20. Comment savoir si Shift est enfoncé dans un événement MouseDown?
- 21. Comment savoir si un rafraîchissement est venu d'une minuterie (C#)
- 22. Comment savoir si un contrôle est actuellement invalide?
- 23. Comment savoir si un assemblage est privé ou public
- 24. Comment savoir si un travail de copie est terminé?
- 25. Comment puis-je savoir si un ModalViewController est affiché?
- 26. Comment savoir si un cookie est déjà là?
- 27. Comment savoir si un fichier est compressé avec gzip?
- 28. Dans MFC, comment savoir si un CComboBox est activé?
- 29. Comment savoir si un UIView est visible et à l'écran?
- 30. Comment savoir si un assembly .NET est dynamique?
Dans la dernière version de Mootools, cette fonction est maintenant appelée 'typeOf': http://mootools.net/docs/core/Core/Core#Core:typeOf – philfreo