Giter Site home page Giter Site logo

Comments (10)

robreczarek avatar robreczarek commented on September 2, 2024

@piecioshka All three objects are now present. Is there something that should be changed in the animal object?

from test-js-practice-zoo.

piecioshka avatar piecioshka commented on September 2, 2024

Constructor in JS are:

function Animal() {
  //...
}
Animal.prototype.xxx = function () {
  // ...
}

😄

from test-js-practice-zoo.

robreczarek avatar robreczarek commented on September 2, 2024

@piecioshka I have revised the code, but am running into issues. Can you please take a look at commit #7

My intent was to mix things up to have properties that are assigned during object instantiation, ones that are private to the internal object, and ones that are exposed via "public" properties.

I'm not sure why I'm not able to push animal objects via the addAnimal method. Also, why do the getGroup and getDiet properties return the function body and not the literals for each?

from test-js-practice-zoo.

piecioshka avatar piecioshka commented on September 2, 2024

@robreczarek nie dam rady chyba po ang to wytłumaczyć 😄 ale spróbuje...

When you defined:

var animals = [];

this is a local variable. So the scope of access starts at 1 line of index.js file and ends in 5 line (when brackets ends).

You should make animals as object member.

this.animals = [];

And in each "method" you should use this as reference to object instance. eg

return this.animals.push(animal);

from test-js-practice-zoo.

piecioshka avatar piecioshka commented on September 2, 2024

@robreczarek btw. please make seconds file test.js where you import index.js file (by require global function) and move whole console.log block to it.

from test-js-practice-zoo.

robreczarek avatar robreczarek commented on September 2, 2024

@piecioshka Możemy też po polsku. Powiedzmy że będzie mi szło raczej koślawo ;)

Usunąłem var i zamieniłem na this, ale nadal mam problem z tym że wypluwa mi funkcję zamiast wartości.

No i teraz jak mam test w oddzielnym pliku, to nie wiem jak zrobić żeby odpaliło. Wyskakują mi ReferenceError.

Probowałem też
var index = require('./index.js');

I w console.log
console.log( 'Welcome to ' + index.myzoo.zooName );

Ale też mam wtedy ReferenceError

from test-js-practice-zoo.

piecioshka avatar piecioshka commented on September 2, 2024

@robreczarek nie nie, piszemy po angielsku 😄

I was created Pull Request with some changes: #4
Please review it.

from test-js-practice-zoo.

robreczarek avatar robreczarek commented on September 2, 2024

@piecioshka I see that you added object definitions for Lion and Elephant, plus a section for module.exports.

This is to expose them for consumption when you require a file, correct? Is this a node.js specific thing?

from test-js-practice-zoo.

piecioshka avatar piecioshka commented on September 2, 2024

This is called "CommonJS syntax".
In definition file you exports, and in setup file you require.

from test-js-practice-zoo.

robreczarek avatar robreczarek commented on September 2, 2024

@piecioshka Got it. Gonna read up on the spec. Seems like this part is a wrap, so I'm closing this out.

from test-js-practice-zoo.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.