[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.00,0:00:03.18,Default,,0000,0000,0000,,Now let's go ahead\Nand make another constructor. Dialogue: 0,0:00:03.18,0:00:07.04,Default,,0000,0000,0000,,So this time,\NI'm going to create a Dalmatian class.... Dialogue: 0,0:00:09.18,0:00:12.55,Default,,0000,0000,0000,,And it's going to be a dog\Nwith the color... Dialogue: 0,0:00:15.77,0:00:19.91,Default,,0000,0000,0000,,[slowly]\Nwhite with black spots. Dialogue: 0,0:00:22.100,0:00:25.05,Default,,0000,0000,0000,,But obviously, I haven't... Dialogue: 0,0:00:25.05,0:00:27.66,Default,,0000,0000,0000,,created any kind of relationship\Nbetween "Dalmation" Dialogue: 0,0:00:27.66,0:00:30.54,Default,,0000,0000,0000,,and "dog" just yet, so if I reload-- Dialogue: 0,0:00:31.63,0:00:33.74,Default,,0000,0000,0000,,oh! Syntax error. Dialogue: 0,0:00:36.35,0:00:39.18,Default,,0000,0000,0000,,Let's see where that is.... Dialogue: 0,0:00:39.18,0:00:42.06,Default,,0000,0000,0000,,Oh, I forgot my parentheses. Dialogue: 0,0:00:42.06,0:00:43.71,Default,,0000,0000,0000,,This is a function. Dialogue: 0,0:00:48.77,0:00:52.88,Default,,0000,0000,0000,,So obviously, if I set "spot" Dialogue: 0,0:00:53.94,0:00:55.71,Default,,0000,0000,0000,,to new... Dialogue: 0,0:00:57.53,0:01:01.33,Default,,0000,0000,0000,,Dalmation, Dal-ma-tion.... Dialogue: 0,0:01:04.32,0:01:06.66,Default,,0000,0000,0000,,Let's try that again. Dialogue: 0,0:01:06.66,0:01:09.00,Default,,0000,0000,0000,,So now "Spot" is a dog, Dialogue: 0,0:01:09.00,0:01:11.19,Default,,0000,0000,0000,,but only the color property\Nis set. Dialogue: 0,0:01:11.19,0:01:14.86,Default,,0000,0000,0000,,So I can say "spot.color,"\Nand that works fine, Dialogue: 0,0:01:14.86,0:01:17.75,Default,,0000,0000,0000,,but if I say "spot.speak," Dialogue: 0,0:01:18.73,0:01:20.13,Default,,0000,0000,0000,,that doesn't work at all. Dialogue: 0,0:01:20.13,0:01:24.03,Default,,0000,0000,0000,,So, in order to define\Nthe inheritance relationship, Dialogue: 0,0:01:24.03,0:01:26.04,Default,,0000,0000,0000,,I need to do something\Na little odd. Dialogue: 0,0:01:26.04,0:01:28.26,Default,,0000,0000,0000,,So let me give you\Na little background first. Dialogue: 0,0:01:28.26,0:01:30.63,Default,,0000,0000,0000,,So, if you're used to a language Dialogue: 0,0:01:30.63,0:01:35.19,Default,,0000,0000,0000,,like C++ or Java or C#, Dialogue: 0,0:01:35.19,0:01:38.25,Default,,0000,0000,0000,,then the way that you define\Nan inheritance relationship Dialogue: 0,0:01:38.25,0:01:41.73,Default,,0000,0000,0000,,is you have a base class,\Nlike dog, Dialogue: 0,0:01:41.73,0:01:44.04,Default,,0000,0000,0000,,and then you extend\Nthat base class Dialogue: 0,0:01:44.04,0:01:47.39,Default,,0000,0000,0000,,by creating a subclass, like Dalmation. Dialogue: 0,0:01:47.39,0:01:49.47,Default,,0000,0000,0000,,So... Dialogue: 0,0:01:49.47,0:01:51.75,Default,,0000,0000,0000,,the way you do it in JavaScript Dialogue: 0,0:01:51.75,0:01:53.01,Default,,0000,0000,0000,,is a little different. Dialogue: 0,0:01:53.01,0:01:56.22,Default,,0000,0000,0000,,So JavaScript is known\Nas a prototypal Dialogue: 0,0:01:56.22,0:01:58.53,Default,,0000,0000,0000,,or "proto-tip-pal" language, Dialogue: 0,0:01:58.53,0:02:01.50,Default,,0000,0000,0000,,where inheritance is based\Non prototypes. Dialogue: 0,0:02:01.50,0:02:02.91,Default,,0000,0000,0000,,So what is a prototype? Dialogue: 0,0:02:02.91,0:02:05.37,Default,,0000,0000,0000,,A prototype is an object. Dialogue: 0,0:02:05.37,0:02:08.22,Default,,0000,0000,0000,,So the way you define\Nan inheritance relationship Dialogue: 0,0:02:08.22,0:02:12.33,Default,,0000,0000,0000,,is you set a base prototype,\Na base object, Dialogue: 0,0:02:12.33,0:02:15.80,Default,,0000,0000,0000,,that the sub-object\Nthat you're creating Dialogue: 0,0:02:15.80,0:02:18.21,Default,,0000,0000,0000,,inherits all the properties from. Dialogue: 0,0:02:18.21,0:02:20.70,Default,,0000,0000,0000,,So instead of extending a class, Dialogue: 0,0:02:20.70,0:02:23.40,Default,,0000,0000,0000,,which is a blueprint\Nfor a set of objects, Dialogue: 0,0:02:23.40,0:02:26.64,Default,,0000,0000,0000,,instead,\Nyou're extending an object Dialogue: 0,0:02:26.64,0:02:29.73,Default,,0000,0000,0000,,by adding additional methods\Nand additional properties Dialogue: 0,0:02:29.73,0:02:32.40,Default,,0000,0000,0000,,to the base set of objects\Nand properties Dialogue: 0,0:02:32.40,0:02:34.53,Default,,0000,0000,0000,,that that object has. Dialogue: 0,0:02:34.53,0:02:36.21,Default,,0000,0000,0000,,So what I want to do, basically, Dialogue: 0,0:02:36.21,0:02:39.00,Default,,0000,0000,0000,,is I want to create a new dog, Dialogue: 0,0:02:39.00,0:02:42.33,Default,,0000,0000,0000,,which is the prototype for all Dalmations, Dialogue: 0,0:02:42.33,0:02:44.61,Default,,0000,0000,0000,,and then I want to inherit Dialogue: 0,0:02:44.61,0:02:47.01,Default,,0000,0000,0000,,that prototype Dialogue: 0,0:02:47.01,0:02:49.95,Default,,0000,0000,0000,,for all Dalmations that I create. Dialogue: 0,0:02:49.95,0:02:52.17,Default,,0000,0000,0000,,The way that works\Nis the constructor, Dialogue: 0,0:02:52.17,0:02:54.39,Default,,0000,0000,0000,,the Dalmation function, Dialogue: 0,0:02:54.39,0:02:58.01,Default,,0000,0000,0000,,has a prototype property,\Nwhich is an object. Dialogue: 0,0:02:58.01,0:02:59.70,Default,,0000,0000,0000,,So whenever you create a function, Dialogue: 0,0:02:59.70,0:03:01.47,Default,,0000,0000,0000,,there's going to be\Na prototype property Dialogue: 0,0:03:01.47,0:03:03.96,Default,,0000,0000,0000,,for that function;\Nlet's take a look at it. Dialogue: 0,0:03:03.96,0:03:06.55,Default,,0000,0000,0000,,So Dalmation, Dialogue: 0,0:03:06.55,0:03:10.73,Default,,0000,0000,0000,,which is a "function.prototype," Dialogue: 0,0:03:11.82,0:03:14.04,Default,,0000,0000,0000,,is an object Dialogue: 0,0:03:14.04,0:03:15.87,Default,,0000,0000,0000,,with a constructor function. Dialogue: 0,0:03:15.87,0:03:17.64,Default,,0000,0000,0000,,And actually,\Nthis constructor function, Dialogue: 0,0:03:17.64,0:03:19.70,Default,,0000,0000,0000,,if I open this up, Dialogue: 0,0:03:19.70,0:03:21.47,Default,,0000,0000,0000,,the function is Dalmation. Dialogue: 0,0:03:21.47,0:03:25.07,Default,,0000,0000,0000,,So an object whose function,\Nconstructor function, Dialogue: 0,0:03:25.07,0:03:27.12,Default,,0000,0000,0000,,is a Dalmation, Dialogue: 0,0:03:27.12,0:03:28.53,Default,,0000,0000,0000,,is the prototype Dialogue: 0,0:03:28.53,0:03:31.35,Default,,0000,0000,0000,,for all Dalmation objects. Dialogue: 0,0:03:31.35,0:03:33.45,Default,,0000,0000,0000,,And there aren't\Nany other properties Dialogue: 0,0:03:33.45,0:03:36.18,Default,,0000,0000,0000,,that are really interesting\Nor useful on this object, Dialogue: 0,0:03:36.18,0:03:38.02,Default,,0000,0000,0000,,because I haven't set any. Dialogue: 0,0:03:38.02,0:03:39.36,Default,,0000,0000,0000,,But for example, Dialogue: 0,0:03:39.36,0:03:40.47,Default,,0000,0000,0000,,if I set Dialogue: 0,0:03:40.47,0:03:42.26,Default,,0000,0000,0000,,[speaking while typing]\N"Dalmation Dialogue: 0,0:03:43.92,0:03:45.76,Default,,0000,0000,0000,,".prototype Dialogue: 0,0:03:46.91,0:03:49.52,Default,,0000,0000,0000,,".legs Dialogue: 0,0:03:49.52,0:03:51.08,Default,,0000,0000,0000,,"= 4...." Dialogue: 0,0:03:52.14,0:03:56.01,Default,,0000,0000,0000,,[speaking while typing]\NAnd then I said, "spot.legs," Dialogue: 0,0:03:56.01,0:03:58.80,Default,,0000,0000,0000,,all of a sudden, Spot,\Nan existing Dalmation, Dialogue: 0,0:03:58.80,0:04:01.65,Default,,0000,0000,0000,,inherits the number of legs Dialogue: 0,0:04:01.65,0:04:05.34,Default,,0000,0000,0000,,from the prototype\Nof the Dalmatian class. Dialogue: 0,0:04:06.37,0:04:11.49,Default,,0000,0000,0000,,So I can do this\Nfor other properties as well. Dialogue: 0,0:04:11.49,0:04:15.52,Default,,0000,0000,0000,,So dog.sound is "bark," Dialogue: 0,0:04:16.99,0:04:21.81,Default,,0000,0000,0000,,"spot.sound"\Nis now "bark" as well. Dialogue: 0,0:04:21.81,0:04:24.54,Default,,0000,0000,0000,,And this will be true\Nfor any other dog that I create. Dialogue: 0,0:04:24.54,0:04:32.87,Default,,0000,0000,0000,,So for example, Dialogue: 0,0:04:32.87,0:04:33.87,Default,,0000,0000,0000,,[speaking while typing]\NRover is new Dalmation as well. Dialogue: 0,0:04:33.87,0:04:35.76,Default,,0000,0000,0000,,rover.legs is four, Dialogue: 0,0:04:36.84,0:04:39.27,Default,,0000,0000,0000,,rover.sound is bark, Dialogue: 0,0:04:39.90,0:04:42.96,Default,,0000,0000,0000,,but I still haven't set a property Dialogue: 0,0:04:44.10,0:04:47.13,Default,,0000,0000,0000,,for speak, so that's still going to be an error. Dialogue: 0,0:04:48.78,0:04:52.17,Default,,0000,0000,0000,,So this suggests a way of doing inheritance, Dialogue: 0,0:04:52.17,0:04:55.26,Default,,0000,0000,0000,,which is to make sure that all of the properties Dialogue: 0,0:04:55.26,0:04:57.69,Default,,0000,0000,0000,,defined for dog are also set Dialogue: 0,0:04:58.20,0:05:01.65,Default,,0000,0000,0000,,for the prototype object for the Dalmatian class, Dialogue: 0,0:05:03.06,0:05:05.22,Default,,0000,0000,0000,,and there's a really easy way of doing that, Dialogue: 0,0:05:05.46,0:05:06.51,Default,,0000,0000,0000,,which is... Dialogue: 0,0:05:07.71,0:05:15.48,Default,,0000,0000,0000,,Dalmation.prototype = new Dog. Dialogue: 0,0:05:18.00,0:05:20.76,Default,,0000,0000,0000,,So Dalmation is going to have a prototype object Dialogue: 0,0:05:20.76,0:05:22.02,Default,,0000,0000,0000,,because it's a function, Dialogue: 0,0:05:23.13,0:05:27.12,Default,,0000,0000,0000,,but I'm overriding that default generic object Dialogue: 0,0:05:27.18,0:05:29.85,Default,,0000,0000,0000,,with a new dog. Dialogue: 0,0:05:30.81,0:05:32.94,Default,,0000,0000,0000,,So any new dog that I create Dialogue: 0,0:05:33.00,0:05:35.07,Default,,0000,0000,0000,,is going to have all of the properties Dialogue: 0,0:05:35.07,0:05:36.39,Default,,0000,0000,0000,,that are defined for dog. Dialogue: 0,0:05:37.08,0:05:39.66,Default,,0000,0000,0000,,So let's go ahead and-- actually let me save this... Dialogue: 0,0:05:40.32,0:05:41.22,Default,,0000,0000,0000,,Save... Dialogue: 0,0:05:42.12,0:05:43.47,Default,,0000,0000,0000,,and then reload, Dialogue: 0,0:05:44.64,0:05:49.71,Default,,0000,0000,0000,,and now, I'm going to create Spot is new Dalmation.