Jump to content

This is incorrect or... Oh I don't know just take a look at it please.


L8V2L

Recommended Posts

The first one is setting the prototype of one object to be another object. In the output you can see that the properties from the prototype were copied into the other object. The second one is just setting bar as a reference to foo.

Link to comment
Share on other sites

The first one is setting the prototype of one object to be another object. In the output you can see that the properties from the prototype were copied into the other object. The second one is just setting bar as a reference to foo.

could you write it out and label each one for visual sake... please.
Link to comment
Share on other sites

Just look at what you posted:

var foo = {name: "foo", zero: 0, one: 1};var bar = {one: "one", 1: 1};bar.__proto__ = foo; // this./*out put:[object Object]   {      [functions]: ,      1: 1,      __proto__: { },      name: "foo",      one: "one",      zero: 0   }*/
The object foo has a property called name, with the value "foo". foo gets set as the prototype of the bar object. In the output of the bar object, you can see that now that object has a property called name, with the value "foo". It got copied from the prototype.Here's a question to see if you understand: in the output, there is a property called one that has the value "one". The prototype also has a property called one, why isn't the value in bar set to 1?
Link to comment
Share on other sites

Just look at what you posted:

var foo = {name: "foo", zero: 0, one: 1};var bar = {one: "one", 1: 1};bar.__proto__ = foo; // this./*out put:[object Object]   {      [functions]: ,      1: 1,      __proto__: { },      name: "foo",      one: "one",      zero: 0   }*/
The object foo has a property called name, with the value "foo". foo gets set as the prototype of the bar object. In the output of the bar object, you can see that now that object has a property called name, with the value "foo". It got copied from the prototype.Here's a question to see if you understand: in the output, there is a property called one that has the value "one". The prototype also has a property called one, why isn't the value in bar set to 1?

 

I'm... happy not the word... excited... but calmly excited of this challenge, and wish you to do more as such in the near future despite my feedback.To answer your question... first it's a basic question. second, there's many ways to say it, it get's overshadow, overwritten. Or to go in detail, the interpreter check the prototype chain to see what property it need to copy from the object's prototype to the instance. If two properties are found in bock the instance and it's object prototype, than the instance property value's override the prototype's value. If just the name of the property, but not the actually value than I thought that the value of the prototype value will get transfer(but as I just try it didn't). I know their are different ways by my post of instancing an object from a object prototype. which is why I ask you to showcase and put a short description by them... or long which ever you want. I'll be thankful either way.
Link to comment
Share on other sites

That's generally correct. The initial value of the property is the one from the prototype. The property in the instance overrides the value from the prototype. Prototype properties can be considered default values, which get changed if the instance changes them.

Link to comment
Share on other sites

1. function Employee(){2. this.name='';3. this.dept='general';4. }5. Employee;6.7. var Manager = new Employee();8. 9. Manager.reports = [];10. 11. Manager;12.13. function WorkerBee(){14. this.projects = [];15. }16. 17. WorkerBee.prototype = new Employee;18. 19. WorkerBee;/*Note: Directly assigning to FunctionName.prototype removes its original prototype's "constructor" property. As a result, (new WorkerBee).constructor yields "Employee" (instead of expected "WorkerBee"). Care must be taken to preserve the original prototype's constructor. For instance, assign the parent to FunctionName.prototype.__proto__ instead. For example, WorkerBee.prototype.__proto__ = new Employee; This way, (new WorkerBee).constructor yields expected "WorkerBee".*/
What's the different between line 7 and 17? And at the bottom, what are they referring to? Speaking of?
Link to comment
Share on other sites

The difference is that line 17 assigns the object to a prototype instead of a variable. What don't you understand about the comment at the end?

This 'assign the parent to FunctionName.prototype.__proto__ instead. For example, WorkerBee.prototype.__proto__ = new Employee; This way, (new WorkerBee).constructor yields expected "WorkerBee".*/'And do you know where I should go next? I like you documentation on mdn, it was up front. I say this, w3school and mdn have the best so far, easier to understand. I read both a least three times already. but I... I don't know where to go.. cause of 'read pic' I need to be able to hover over one site, or I'll be every where. Please, do you know where I can go next?
Link to comment
Share on other sites

What don't you understand about that? You know what a prototype is, right?You should read a book, and start writing code. Design a small Javascript program that you know will use the things you want to learn about.

Link to comment
Share on other sites

This 'assign the parent to FunctionName.prototype.__proto__ instead. For example, WorkerBee.prototype.__proto__ = new Employee; This way, (new WorkerBee).constructor yields expected "WorkerBee".*/'What is it doing? is it the same as WorkerBee.prototype = new Employee?If I can find a book that have less talking and more learning, I want a book that is like w3school or and mdn guide, straight to the point, with picture.DO you know a book like that?

Link to comment
Share on other sites

is it the same as WorkerBee.prototype = new Employee?

No it's not the same, it is explaining the differences between the two.I don't have suggestions for specific books. I would tend to believe that the best selling books have something good to offer.
Link to comment
Share on other sites

can be converted into a recursive function and a call to that function:function loop(x) {   if (x >= 10) // "x >= 10" is the exit condition (equivalent to "!(x < 10)")      return;   // do stuff   loop(x + 1); // the recursive call}loop(0);
So a recursive function, is a function that can call it self... but every function can do that.Will not every function, you have function that can call them self one time i.e. (function(param0, param1, paramN){}()); or (function(param0, param1, paramN){})(); or they can be attach to a variable i.e. var fun = (function(){})(); or var fun = (function(){}());If some of you don't want to be bother with my question anymore, just give me a link to where I can go and ask them. Edited by L8V2L
Link to comment
Share on other sites

It is not a function that can call itself, or a function that is stored in a variable, or an immediately-invoked function (neither of which call themselves), it is a function that does call itself.

Link to comment
Share on other sites

The reason that function is recursive is because it calls itself at the end of the function. The call to loop(0) is not part of what the function does. This is what the function does:

function loop(x) {   if (x >= 10) // "x >= 10" is the exit condition (equivalent to "!(x < 10)")      return;   // do stuff   loop(x + 1); // the recursive call}
Link to comment
Share on other sites

It's not doing anything when I long it in the console.log(loop(0));And I don't want to read another author(look what I know, and spend money and time learning nothing) book. Those book feel like a lot of the tutorial website, just out to waste your time. I want a guide, a guide straight to the point with i.e. every step of the way. I read over w3school three time and mdn guide three time. But I don't feel like I'm advancing. I'm looking at this as a career... I want to make games with this.Do you know any guide books on html, css, javascript; html5? Do you know any guide books for beginner leading toward intermediate, crossing over to advance, and introducing technical. Not where you have a block of words with the author talking about himself, or what he feel or believe. but straight to HERE! THIS IS WHAT YOU NEED TO KNOW, AND HERE MORE REFERENCE IF YOU WANT TO KNOW MORE! book.

Link to comment
Share on other sites

var x = 3;var y = 4;x+= y; // 7y-= x; // -3var z = 0;/*//z-=y;z += x; // 7z-=y; // 3//z += x;*/z-=y;//10// how is this possible?z += x;//10//how is this possible?console.log('x+=y:' + x + 'n' + 'y-=x:' + y + 'r' + 'z -=y:' + z + 'n' + 'z +=x:' + z);/*x+=y:7y-=x:-3z -=y:10z +=x:10*/
Edited by L8V2L
Link to comment
Share on other sites

It's not doing anything when I long it in the console.log(loop(0));

The function doesn't return anything, there's nothing to log.

Those book feel like a lot of the tutorial website, just out to waste your time.

Sorry you feel that way, I disagree. If you did a little research then you could find some books written by some very well-known programmers, like Douglas Crockford. Like us, their goal is to teach, not waste peoples' time.

I read over w3school three time and mdn guide three time. But I don't feel like I'm advancing.

That's because online tutorials are shallow. Documentation is just documentation, it's not a learning manual. One of the most popular books has 1100 pages, do you think you're going to find more information in a free online tutorial or an 1100 page book?

I'm looking at this as a career... I want to make games with this.

Then seriously, move beyond online tutorials. The next step is books. The step after that is classes. Find some computer science classes at a community college. Don't focus too much on Javascript specifically, you need to understand computer science theory to be an effective developer.People don't go through online tutorials to learn how to repair engines, or build houses, there's no reason that developing applications is any different. It is a trade, a craft, and an art. If you want to be good then you need to learn from someone good. Douglas Crockford has some material online, look at that for a start if you really don't want a book for whatever reason.http://shop.oreilly.com/product/0636920027065.dohttp://shop.oreilly.com/product/9780596805531.dohttp://shop.oreilly.com/product/9780596517748.dohttp://shop.oreilly.com/product/9781593275402.do
  • Like 2
Link to comment
Share on other sites

The function doesn't return anything, there's nothing to log.Sorry you feel that way, I disagree. If you did a little research then you could find some books written by some very well-known programmers, like Douglas Crockford. Like us, their goal is to teach, not waste peoples' time.That's because online tutorials are shallow. Documentation is just documentation, it's not a learning manual. One of the most popular books has 1100 pages, do you think you're going to find more information in a free online tutorial or an 1100 page book?Then seriously, move beyond online tutorials. The next step is books. The step after that is classes. Find some computer science classes at a community college. Don't focus too much on Javascript specifically, you need to understand computer science theory to be an effective developer.People don't go through online tutorials to learn how to repair engines, or build houses, there's no reason that developing applications is any different. It is a trade, a craft, and an art. If you want to be good then you need to learn from someone good. Douglas Crockford has some material online, look at that for a start if you really don't want a book for whatever reason.http://shop.oreilly.com/product/0636920027065.dohttp://shop.oreilly.com/product/9780596805531.dohttp://shop.oreilly.com/product/9780596517748.dohttp://shop.oreilly.com/product/9781593275402.do

Appreciate the words and links. Please let me rephrase, I understand by the accusations of programming raving about these books... What I mean to say is, I come to like the here it is approach. I'm not saying them books aren't good read, I'm saying I come to love to here it is approach, where their is no talking, their is no joking, just the information, and an explain. I can come to see as those books will contain the author's experience, knowledge, skills, and trick they learn upon the way of their career. I will come around to sitting down, and picking them up to read. But I'm mostly interested in a straight forward book, it can have a little bit of history, and did you know parts in it, but for mostly, I come to love, here it is. Cause with that, with every sentences, I'm gaining knowledge on the subject at hand, not of the author speaking of something which ties in to the we are talking about, but add no real value/knowledge for me to know. I use to think this approach was boarding, but I come to value it, I come to see cause the fact that I want to learn this, I want to not waste time with it, I want to not read long books which a percent of it contain amusement, and laughter(unless it ties directly into the subject to where I'll get knowledge from it).Please note, I have not excuse non of the books you gave me, I just wish to countertrade on memorizing myself with the components of JavaScript, and it's syntax.Thanks for talking the time to reply to my post.
Link to comment
Share on other sites

I want to not waste time with it, I want to not read long books which a percent of it contain amusement, and laughter

That's funny, coming from someone who posts conversations between himself and a programming language, or movie quotes.

Please note, I have not excuse non of the books you gave me, I just wish to countertrade on memorizing myself with the components of JavaScript, and it's syntax.

If you haven't yet, you need to start writing code. You don't learn how to program by reading, you learn how to program by writing.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...