JavaScript Training
Goal Trainers Format
• Lecture
• Exercises
• Ask Questions!
• bitovi/js-training
What is “this”?
var dog = {
barkCount: 0,
bark: function(){
this.barkCount++;
}
}
dog.bark();
var dog = {
barkCount: 0,
bark: function(){
this.barkCount++;
}
}
var bark = dog.bark;
bark();
window
Person = function(name){
this.name = name;
}
var p = new Person("Justin Meyer")
Person = function(name){
this.name = name;
}
var p = Person(“Justin Meyer”)
window
var dog = {
barkCount: 0,
bark: function(barks) {
this.barkCount+=barks;
}
},
cat = {
barkCount: 0
}
dog.bark.call(cat, 1);
Summary
Rule Example
[[Call]] operator
var bark = function() {};
bark();
Dot [[Call]] operator
var puppy = { … };
puppy.bark();
‘new’ keyword var puppy = new Dog();
‘call’ or ‘apply’
var puppy = { … };
Dog.bark.call(puppy, 1);
Dot.
__proto__
var foo = {}; //same as new Object()
foo.toString();
fn fnOBJECT
OBJECT
PROTOTYPE toString
foo
Object
null
// -> [object Object]
toString()
this
Exercise
Write the dot operator as if it was implemented in JS.
var Person = function(name) {
this.name = name;
}
Person.prototype.isPerson = true;
var person = new Person('Smith');
DOT(person, 'name'); //person.name
DOT(person, 'isPerson'); //person.isPerson
Hints:
• DOT takes the object and the property
• DOT must walk up the __proto__ chain
• object.hasOwnProperty(“PROPERTY_NAME”) returns if an object has
a ‘direct’ property.
Exercise
Write the dot [[call]] operator as if it was implemented in JS.
var Person = function(name) {
this.name = name;
}
Person.prototype.speak = function(){
console.log('Hello! ' + this.name);
}
var person = new Person('Smith');
DOTCALL( obj, propertyName, args );
DOTCALL( person, 'speak’ , [] ); //person.speak()
Hints:
• DOTCALL must retain context
foo getDay
Summary
__proto__
var d = new Date();
d.foo = 'bar';
d.hasOwnProperty();
__proto__
hasOwnProperty
this
OBJECT
PROTOTYPEOBJECT
DATE
PROTOTYPE
✓❌ ❌
d

More Related Content

PPTX
Prototypes
PDF
Python - Lecture 4
KEY
JavaScript Classes and Inheritance
PDF
JS OO and Closures
PDF
Python fundamentals - basic | WeiYuan
PDF
There's a Prolog in your Scala!
PDF
Icsug dev day2014_road to damascus - conversion experience-lotusscript and @f...
PDF
WordCamp Portland 2018: PHP for WordPress
Prototypes
Python - Lecture 4
JavaScript Classes and Inheritance
JS OO and Closures
Python fundamentals - basic | WeiYuan
There's a Prolog in your Scala!
Icsug dev day2014_road to damascus - conversion experience-lotusscript and @f...
WordCamp Portland 2018: PHP for WordPress

What's hot (20)

PDF
Inheritance & polymorphism java oop
PPTX
Dr iterate
PPTX
Building a horizontally scalable API in php
PDF
Java script objects 1
 
PDF
Purely functional data structures
PPTX
Switching from java to groovy
PDF
Thesis presentation Samuel Lampa
PDF
Chapter 1 python basics
PPTX
Grails queries
PPTX
PDF
Useful javascript
PDF
JRuby hacking guide
PPT
Power shell object
PPTX
Power shell
PDF
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
PPTX
Learn python - for beginners - part-2
PDF
Functional Programming with Groovy
PPTX
Grails GORM - You Know SQL. You Know Queries. Here's GORM.
Inheritance & polymorphism java oop
Dr iterate
Building a horizontally scalable API in php
Java script objects 1
 
Purely functional data structures
Switching from java to groovy
Thesis presentation Samuel Lampa
Chapter 1 python basics
Grails queries
Useful javascript
JRuby hacking guide
Power shell object
Power shell
PromptWorks Talk Tuesdays: Ray Zane 1/17/17 "Elixir Is Cool"
Learn python - for beginners - part-2
Functional Programming with Groovy
Grails GORM - You Know SQL. You Know Queries. Here's GORM.
Ad

Viewers also liked (6)

PPTX
Closures
PPTX
Types, Operators and Primitives
PPTX
Events - Part 2
PPTX
Comparisons
PPTX
Element Styles and Positioning
PPTX
Basic JS
Closures
Types, Operators and Primitives
Events - Part 2
Comparisons
Element Styles and Positioning
Basic JS
Ad

Similar to Context (20)

KEY
CoffeeScript - A Rubyist's Love Affair
PDF
Javascript development done right
KEY
JavaScript @ CTK
PPTX
KEY
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽
PDF
ES2015 New Features
PDF
Damn Fine CoffeeScript
PPT
Tips and Tricks of Developing .NET Application
PPTX
Ian 20150116 java script oop
PDF
Elm: give it a try
PDF
CoffeeScript
PPT
JavaScript Functions
PPT
Fantom and Tales
PPTX
ES6 and AngularAMD
DOC
Jsphp 110312161301-phpapp02
PPT
OO JS for AS3 Devs
PPTX
Javascript basics
PPTX
LinkedIn TBC JavaScript 100: Intro
PDF
The Ring programming language version 1.10 book - Part 40 of 212
ODP
Learnjs
CoffeeScript - A Rubyist's Love Affair
Javascript development done right
JavaScript @ CTK
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽
ES2015 New Features
Damn Fine CoffeeScript
Tips and Tricks of Developing .NET Application
Ian 20150116 java script oop
Elm: give it a try
CoffeeScript
JavaScript Functions
Fantom and Tales
ES6 and AngularAMD
Jsphp 110312161301-phpapp02
OO JS for AS3 Devs
Javascript basics
LinkedIn TBC JavaScript 100: Intro
The Ring programming language version 1.10 book - Part 40 of 212
Learnjs

Recently uploaded (20)

PPTX
Tartificialntelligence_presentation.pptx
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Developing a website for English-speaking practice to English as a foreign la...
PPTX
Modernising the Digital Integration Hub
PPT
Geologic Time for studying geology for geologist
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
STKI Israel Market Study 2025 version august
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
August Patch Tuesday
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Architecture types and enterprise applications.pdf
Tartificialntelligence_presentation.pptx
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Univ-Connecticut-ChatGPT-Presentaion.pdf
A contest of sentiment analysis: k-nearest neighbor versus neural network
Zenith AI: Advanced Artificial Intelligence
Chapter 5: Probability Theory and Statistics
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Enhancing emotion recognition model for a student engagement use case through...
Developing a website for English-speaking practice to English as a foreign la...
Modernising the Digital Integration Hub
Geologic Time for studying geology for geologist
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
DP Operators-handbook-extract for the Mautical Institute
STKI Israel Market Study 2025 version august
Assigned Numbers - 2025 - Bluetooth® Document
1 - Historical Antecedents, Social Consideration.pdf
August Patch Tuesday
NewMind AI Weekly Chronicles – August ’25 Week III
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Architecture types and enterprise applications.pdf

Context

  • 1. JavaScript Training Goal Trainers Format • Lecture • Exercises • Ask Questions! • bitovi/js-training
  • 3. var dog = { barkCount: 0, bark: function(){ this.barkCount++; } } dog.bark();
  • 4. var dog = { barkCount: 0, bark: function(){ this.barkCount++; } } var bark = dog.bark; bark(); window
  • 5. Person = function(name){ this.name = name; } var p = new Person("Justin Meyer")
  • 6. Person = function(name){ this.name = name; } var p = Person(“Justin Meyer”) window
  • 7. var dog = { barkCount: 0, bark: function(barks) { this.barkCount+=barks; } }, cat = { barkCount: 0 } dog.bark.call(cat, 1);
  • 8. Summary Rule Example [[Call]] operator var bark = function() {}; bark(); Dot [[Call]] operator var puppy = { … }; puppy.bark(); ‘new’ keyword var puppy = new Dog(); ‘call’ or ‘apply’ var puppy = { … }; Dog.bark.call(puppy, 1);
  • 10. __proto__ var foo = {}; //same as new Object() foo.toString(); fn fnOBJECT OBJECT PROTOTYPE toString foo Object null // -> [object Object] toString() this
  • 11. Exercise Write the dot operator as if it was implemented in JS. var Person = function(name) { this.name = name; } Person.prototype.isPerson = true; var person = new Person('Smith'); DOT(person, 'name'); //person.name DOT(person, 'isPerson'); //person.isPerson Hints: • DOT takes the object and the property • DOT must walk up the __proto__ chain • object.hasOwnProperty(“PROPERTY_NAME”) returns if an object has a ‘direct’ property.
  • 12. Exercise Write the dot [[call]] operator as if it was implemented in JS. var Person = function(name) { this.name = name; } Person.prototype.speak = function(){ console.log('Hello! ' + this.name); } var person = new Person('Smith'); DOTCALL( obj, propertyName, args ); DOTCALL( person, 'speak’ , [] ); //person.speak() Hints: • DOTCALL must retain context
  • 13. foo getDay Summary __proto__ var d = new Date(); d.foo = 'bar'; d.hasOwnProperty(); __proto__ hasOwnProperty this OBJECT PROTOTYPEOBJECT DATE PROTOTYPE ✓❌ ❌ d

Editor's Notes

  • #4: Tom: animations need to stay the same, but just make sure the font/theme matches Justin’s slides
  • #5: Tom: animations need to stay the same, but just make sure the font/theme matches Justin’s slides
  • #6: Tom: animations need to stay the same, but just make sure the font/theme matches Justin’s slides
  • #7: Tom: animations need to stay the same, but just make sure the font/theme matches Justin’s slides
  • #8: Tom: animations need to stay the same, but just make sure the font/theme matches Justin’s slides
  • #9: Tom: grid should be prettier, matching Justin’s theme.
  • #11: Tom: Animations should remain, but shapes/theme should match Justin’s
  • #15: Tom: Summary slide; Animations should remain, but shapes/theme should match Justin’s