Delving into JS

I’m sorry if I misunderstand you.

But I could do shippingCost(“pizza”); OR i could do Object.shippingCost(“pizza”);.

For arguments sake, why is Object. needed? I pass through the …

OHHH wait.

If I just straight up called hte function like that, I’d have to use a switch case or something to determine whcih cost to do? But with OOP I clean up my code and make it so my shippingCost function is called like…Pizza.shippingCost() (I made that shippingCost a prototype so all my “food” in this example gets the shippingCost method…

I feel like I’m rambling. Does any of this make sense?

I could ‘yep’ back at you… but I don’t deal with this kind of scarce dialog. When it comes to inheritance in javascript you DO have prototypal and classical, and we have this view even since the early Douglas Crockford days:

http://javascript.crockford.com/inheritance.html

http://javascript.crockford.com/prototypal.html

You are probably thrown off by the prototype keyword. It’s an honest mistake for every JS inheritance newbie.

Here’s more food for thought: http://vimeo.com/69255635

Yeah, that’s right. You’re also avoiding problems with having global variables and functions: you can have many different types of object that have a method named getShippingCost() without any name clashes or overwriting of one variable/function by another.

Let’s talk jQuery, I assume is more familiar. The jQuery object is $. You know that because you use it every time you access its properties and methods, right? What if that was not the case and all the jQuery properties and methods would reside globally?

Sorry but I don’t know jQuery. For JS/Jquery my knowledge up until a few days ago was the ability to copy scripts and modify to work for me. I read online that fundamental Javascript knowledge should be learned first.

And thank you @fretburner for that clarification

jQuery at its core is simply a javascript object with properties and methods. jQuery was an example of well written code.

jQuery — New Wave JavaScript

has adapted to modern thinking in javascript and now comes in modules, has nodejs support, has grunt support.

You could learn a lot about javascript studying jQuery back in the day, and you can still learn a lot about modern javascript studying jQuery today: https://github.com/jquery/jquery/tree/master/src

What I consider proper javascript knowledge is objects, inheritance, closures, modules. Modern jQuery teaches you all that. Modern javascript also requires one to take a look at nodejs. You’ve got a long road ahead, DOM API is simply not relevant yet.

I’m not going to mix my knowledge of Javascript and Jquery…I’ll stick to Javascript for now. Thanks.

jQuery IS javascript. I’m not telling you to use jQuery, I’m telling you to look at the source code to see how they code it as a good way to learn javascript key concepts. Also take a look at underscore: http://underscorejs.org/docs/underscore.html. See the patterns they use.

1 Like

I don’t want to mix up technologies. Differentiating Jquery and Javascript might be easy for you but there is A LOT of Javascript. I don’t want to mix up my technologies.

I’m not going to look at Jquery for a while. I can stick to reading and looking at examples given.

You don’t get it: jQuery is not a different technology, is just a javascript object. Somebody has been feeding you nonsense. It’s like saying <header> is a different technology then <div>.

No I understand. Why stray from my learning path where I have a structured plan? That’s silly. I’m not going to take your suggestion. Just drop it.

You don’t understand just yet. Good luck with the plan. And if you ever came across building your own library code, remember what I told you and take a look at the patterns in the jQuery or underscore source code. It should make things clearer and easier for you. Also, it’s plain rude to say “drop it” to someone that took the time to answer to your questions. If anything, you should perhaps listen more careful and you should be thankful for every bit of the insight you get. It might be that some things just go over your head right now.

jQuery is just a JavaScript object that someone else has written and made available for others to use. You use it if you need most of the functionality it provides and you use something else if you only need a small fraction of the functionality.

Most of the jQuery calls have a fairly short native JavaScript equivalent as much of the functionality that jQuery was written to provide has now been added to JavaScript itself.

You were getting too pushy even though I plainly said I didn’t want to do it. So I escalated into telling you to drop it. I’m sorry you feel offended but it resorted to that.

@felgall, nice post describing jQuery.

[quote=“felgall, post:33, topic:99388”]
jQuery is just a JavaScript object that someone else has written and made available for others to use. You use it if you need most of the functionality it provides and you use something else if you only need a small fraction of the functionality.[/quote]

That’s the old jQuery. The new jQuery is AMD compatible. This means it’s modular and if you need a small fraction of the functionality you don’t use something else, you build and include only the jQuery modules you need.

jQuery has been optimized to work with a variety of browsers automatically. Browsers don’t implement fully the same native javascript.

OK, that’s enough. Let’s not derail the discussion into a JavaScript vs. jQuery debate
The OP has clearly stated they do not want to get into the extra learning curve involved with learning jQuery for now, and want to get a grip on JavaScript. Please, lets leave it at that.

2 Likes

let me quote Douglas Crockford from the above source

[…] I now see my early attempts to support the classical model in JavaScript as a mistake.

And this proves your “nope” point how? ES6 adds class,private and other classical inheritance concepts.

syntactical sugar. just because you shortcut the constructor syntax doesn’t make it native classical inheritance.

1 Like

To make it easier for those who only know classical inheritance to generate JavaScript’s prototype inheritance using something that looks like what they are used to. It looks like classical but implements prototypical inheritance (since that’s the only type of inheritance that JavaScript supports).