Working with Static Properties on a Class

InstructorTyler Clark

Share this video with your friends

Send Tweet

Classes are syntactic sugar over functions and functions are also referred to as "callable" objects. So it is possible to treat a function like an object and give them key / value properties like objects. The static keyword gives us the ability to assign a key / value property to a class itself, not an instance of that class. This lesson will walk you through using the static keyword and even show how to replicate it with regular functions.

Viktor Soroka
~ 5 years ago

Interestingly enough that extends has worked just fine with functions and not with classes only. Good to know:)

dung ho
~ 5 years ago

So what if I put the keyword this inside static function ? what will be the execute scope of it ?

Tyler Clarkinstructor
~ 5 years ago

So what if I put the keyword this inside static function ? what will be the execute scope of it ?

Hey doug check out the lessons within this course on using this. It depends on how the static property is called... this is determined at runtime. In this scenario, this is the Square class.

class Square {
  static whoAmI(){
    return this
  }
}

Square.whoAmI()
Tyler Clarkinstructor
~ 5 years ago

Sorry, I spelt your name wrong! Meant to put dung!

Hans Brough
~ 4 years ago

"They cannot be called on instances of the class. If you use the new keyword against this, you cannot easily access the static properties." - this could be useful for private methods and props (?) e.g. what problem does this help us solve?