Comments (10)
@piecioshka All three objects are now present. Is there something that should be changed in the animal object?
from test-js-practice-zoo.
Constructor in JS are:
function Animal() {
//...
}
Animal.prototype.xxx = function () {
// ...
}
😄
from test-js-practice-zoo.
@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.
@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.
@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.
@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.
@robreczarek nie nie, piszemy po angielsku 😄
I was created Pull Request with some changes: #4
Please review it.
from test-js-practice-zoo.
@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.
This is called "CommonJS syntax".
In definition file you exports
, and in setup file you require
.
from test-js-practice-zoo.
@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)
- Test project name convention HOT 4
- How to run a demo? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from test-js-practice-zoo.