File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11/* The for principles of "this";
22* in your own words. explain the four principle for the "this" keyword below.
33*
4- * 1.
5- * 2.
6- * 3.
7- * 4.
4+ * 1. window behind the scenes in the browser
5+ * 2. explicit call bind apply are methods on objects called explicitly
6+ * 3. new creating a new object based off a constructor
7+ * 4. implicit using this inside of an object
88*
99* write out a code example of each explanation above
1010*/
1111
1212// Principle 1
1313
1414// code example for Window Binding
15+ function aFunction ( ) {
16+ console . log ( this ) ;
17+ }
1518
1619// Principle 2
1720
1821// code example for Implicit Binding
19-
22+ const aObject = {
23+ name : 'Jonathan' ,
24+ method1 : function ( ) {
25+ console . log ( `My name is ${ this . name } ` ) ;
26+ }
27+ }
2028// Principle 3
2129
2230// code example for New Binding
23-
31+ function CapitalRequired ( name , sport ) {
32+ this . name = name ;
33+ this . sport = sport ;
34+ }
35+ const jonathan = new CapitalRequired ( "Jonathan" , "running" ) ;
2436// Principle 4
2537
26- // code example for Explicit Binding
38+ // code example for Explicit Binding
39+ function CapitalRequired2 ( secondatrributes ) {
40+ CapitalRequired . call ( this , secondatrributes ) ; // THIS IS EXPLICIT.
41+ //something new would go here.
42+ }
43+
44+ CapitalRequired2 . prototype = Object . create ( CapitalRequired . prototype ) ; //inherit
45+
46+ const jonathanChild = new CapitalRequired2 ( "Jack" , "running" ) ;
You can’t perform that action at this time.
0 commit comments