Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]Funkcja nie jest funkcją.
MeGusta
post
Post #1





Grupa: Zarejestrowani
Postów: 155
Pomógł: 0
Dołączył: 6.07.2015

Ostrzeżenie: (10%)
X----


Witam,
Czemu pluje mi, że funkcja nie jest funkcją? Dodam, że jeśli umieszczę jej wywołanie poza forEach normalnie działa.

  1.  
  2. this.drawInventory = function(item)
  3. {
  4. document.getElementById('player_inv').innerHTML += item;
  5. return false;
  6. };
  7.  
  8. this.inventory.forEach(function(item) {
  9. this.drawInventory(item);
  10. });


Błąd:
Uncaught TypeError: this.drawInventory is not a function
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
MeGusta
post
Post #2





Grupa: Zarejestrowani
Postów: 155
Pomógł: 0
Dołączył: 6.07.2015

Ostrzeżenie: (10%)
X----


Kurcze, no juz w morde nie wiem, jak nie nadpisywało tak nie nadpisuje.

  1. var Player = function(options) {
  2.  
  3. this.name = null;
  4. this.level = 0;
  5.  
  6. this.init();
  7.  
  8. };
  9.  
  10.  
  11. Player.prototype = {
  12. constructor: Player,
  13. init: function() {
  14. var self = this;
  15. this.getData({ task: 1 }, function(d) {
  16.  
  17. var data = d.split('|');
  18. self.name = data[0];
  19. self.level = data[1];
  20. console.log(self.name) // zwraca prawidłowo
  21. });
  22. },
  23. getData: function(data, onDone) {
  24. $.ajax({ type: 'POST', url: 'engine.php', data: data}).done(onDone);
  25. },
  26. getName: function()
  27. {
  28. return this.name;
  29. }
  30. };
  31.  
  32. var player = new Player();
  33.  
  34. console.log(player.getName()); // zwraca null


Jakieś pomysły?

Ten post edytował MeGusta 20.08.2016, 13:22:16
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 11.10.2025 - 00:53