19. More Kinds of Methods


#1



https://www.codecademy.com/courses/spencer-sandbox/2/7?curriculum_id=506324b3a7dffd00020bf661#


Hello,
I don't exactly understand , why we need to use 'this.' as we already defined the method to the object.


return this.sideLength * 4;


#2

@gigaslayer63800,

Try, and use following code

var square = new Object();
    square.sideLength = 6;
    square.calcPerimeter = function() {
          return this.sideLength * 4;
    };
// help us define an area method here
    square.calcArea= function() {
         return sideLength * this.sideLength;
    };
var sideLength = 20;
var p = square.calcPerimeter();
var a = square.calcArea();
    console.log(a + " " + p);

And you will see that calcPerimeter() Method
will use
a sideLength =global= variable number Value 20
and a this.sideLength Object number Value 6

== discussions / opinions ==
javascript this explained site:stackoverflow.com
http://stackoverflow.com/questions/3127429/how-does-the-this-keyword-work
== guidance ==
www.crockford.com
http://javascript.crockford.com/code.html
http://javascript.crockford.com/survey.html
https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript
https://www.codecademy.com/forum_questions/55f03d4b93767651db0005b3
++++++++++++++++++++++++++++++++++++++++++++++++
www.developer.mozilla.org/en-US/docs/Web/JavaScript/Guide

+++ this explained

Reference::

google search
== the Book ==
javascript this site:developer.mozilla.org
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this
Have a read through
http://stackoverflow.com/questions/4354418/var-vs-this-vs-constructor-parameter-variables
and
http://javascriptweblog.wordpress.com/2010/08/30/understanding-javascripts-this/