first pull request - #719
Conversation
| the major diffrence between methods and functions is that methods are tied to a specific class | ||
| closure is the accessibility of a variable in its lixicle scope | ||
| there is default binding where 'this' refers to global scope, implicit binding is when "this" is called by a preceding dot the object for it is "this", new binding is when a constructor function is in use "this" refers to the object created by that constructor function, explicit binding is when javascripts call or apply method is in use and "this" is explicitly defined. | ||
| super is a keyword use to call functions from parent object onto child object. No newline at end of file |
There was a problem hiding this comment.
Yes; its primary use is just with the constructor (super(arguments))! Using other methods with super isn't as common.
| this.weight = attributes.weight || 'weight unkown'; | ||
| this.length = attributes.length || 'length unkown'; | ||
| this.period = attributes.period || 'period unkown'; | ||
| } |
There was a problem hiding this comment.
It's smart to make a class here and use its constructor for your objects! You actually weren't required to make this that advanced, though. You could've just made three objects without using a class or constructor function.
| weight: '7000kg', | ||
| length: '12m', | ||
| period: 'Late Cretaceious' | ||
| }) |
There was a problem hiding this comment.
For example, doing this without your class:
const tyrannosaurus = {
name: 'tyrannosaurus',
diet: 'carnivorous',
weight: '7000kg',
length: '12m',
period: 'Late Cretaceious'
};| function add(w,e) { | ||
| return w + e; | ||
| } | ||
| function multiply(w,e) { |
There was a problem hiding this comment.
What do w and e represent and mean? Choosing meaningful variable names is better than single-letter variables!
| Formula for cuboid volume: length * width * height | ||
| */ | ||
|
|
||
| CuboidMaker.prototype.Volume = function(){ |
There was a problem hiding this comment.
Typically we use lowercase, at least for single word variables (we specifically use camelCase for multi-word variables in JavaScript) for variables. Try to keep to this style! It'll pay off in time so that you don't have to go back and wonder how you capitalized a certain name:
CuboidMaker.prototype.volume = function(){ ... }Classes (or, at least, constructors built using class syntax) and constructor functions are one of the few exceptions (where we use PascalCase).
| // console.log(cuboid.volume()); // 100 | ||
| // console.log(cuboid.surfaceArea()); // 130 | ||
| console.log(cuboid.volume()); // 100 | ||
| console.log(cuboid.surfaceArea()); // 130 |
There was a problem hiding this comment.
You seem to be missing a declaration of cuboid here. Try using this object for your dimensions for your cuboid variable next time:
{ length: 5, width: 4, height: 5 }| return this.length * this.width * this.height; | ||
| } | ||
|
|
||
| surfacArea(){ |
There was a problem hiding this comment.
Also note the spelling(/capitalization) errors here:
surfacArea should be surfaceArea
and
Volume should be volume
since that's how they're called down below
No description provided.