context
stringlengths
545
71.9k
questionsrc
stringlengths
16
10.2k
question
stringlengths
11
563
overview paleolithic groups developed increasingly complex tools and objects made of stone and natural fibers . language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era . technological innovation stone tools are perhaps the first cultural artifacts which historians can use to reconstruct the worlds of paleolithic peoples . in fact , stone tools were so important in the paleolithic age that the names of paleolithic periods are based on the progression of tools : lower paleolithic , upper paleolithic , mesolithic ( middle stone age ) , and neolithic ( new stone age ) . $ ^1 $ stone tools also give us insight into the development of culture . anthropologists think paleolithic people likely hunted , foraged , and employed a communal system for dividing labor and resources . anthropologists have inferred this by drawing analogies to modern hunter-gatherer groups and by interpreting cave art which depicts group hunting . by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers . it is likely that many tools made out of materials besides stone were prevalent but simply did not survive to the present day for scientists to observe . one exception is the neolithic “ ice man ” , found by two hikers in the ötztal alps , who was preserved in ice for 5,000 years ! he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures . without the aid of language , these things would likely have been impossible . examinations of the craniums of archaic homo sapiens suggest large brains with indentations that imply the development of brain areas associated with speech . exactly how humans developed a capacity for language is a matter of considerable debate . however , the historical record shows that language allowed for increasingly complex social structures , with an enhanced capacity for deliberation , morality , spirituality , and meaning-making . artwork such as cave painting and portable art demonstrates creativity and group structures as well . they show an interest in sharing knowledge , expressing feelings , and transmitting cultural information to later generations . though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic . such an object shows a desire to create beautiful figurines , but some also suggest that objects like this are tied to an interest in human fertility . what do you think ? what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ? what do you think was the purpose of paleolithic art such as cave paintings and figurines ?
he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures .
did we decided/forced/forgot/still use the foreign language ?
overview paleolithic groups developed increasingly complex tools and objects made of stone and natural fibers . language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era . technological innovation stone tools are perhaps the first cultural artifacts which historians can use to reconstruct the worlds of paleolithic peoples . in fact , stone tools were so important in the paleolithic age that the names of paleolithic periods are based on the progression of tools : lower paleolithic , upper paleolithic , mesolithic ( middle stone age ) , and neolithic ( new stone age ) . $ ^1 $ stone tools also give us insight into the development of culture . anthropologists think paleolithic people likely hunted , foraged , and employed a communal system for dividing labor and resources . anthropologists have inferred this by drawing analogies to modern hunter-gatherer groups and by interpreting cave art which depicts group hunting . by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers . it is likely that many tools made out of materials besides stone were prevalent but simply did not survive to the present day for scientists to observe . one exception is the neolithic “ ice man ” , found by two hikers in the ötztal alps , who was preserved in ice for 5,000 years ! he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures . without the aid of language , these things would likely have been impossible . examinations of the craniums of archaic homo sapiens suggest large brains with indentations that imply the development of brain areas associated with speech . exactly how humans developed a capacity for language is a matter of considerable debate . however , the historical record shows that language allowed for increasingly complex social structures , with an enhanced capacity for deliberation , morality , spirituality , and meaning-making . artwork such as cave painting and portable art demonstrates creativity and group structures as well . they show an interest in sharing knowledge , expressing feelings , and transmitting cultural information to later generations . though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic . such an object shows a desire to create beautiful figurines , but some also suggest that objects like this are tied to an interest in human fertility . what do you think ? what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ? what do you think was the purpose of paleolithic art such as cave paintings and figurines ?
he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures .
did we decide or were we forced to change the foreign language that we used to speak ?
overview paleolithic groups developed increasingly complex tools and objects made of stone and natural fibers . language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era . technological innovation stone tools are perhaps the first cultural artifacts which historians can use to reconstruct the worlds of paleolithic peoples . in fact , stone tools were so important in the paleolithic age that the names of paleolithic periods are based on the progression of tools : lower paleolithic , upper paleolithic , mesolithic ( middle stone age ) , and neolithic ( new stone age ) . $ ^1 $ stone tools also give us insight into the development of culture . anthropologists think paleolithic people likely hunted , foraged , and employed a communal system for dividing labor and resources . anthropologists have inferred this by drawing analogies to modern hunter-gatherer groups and by interpreting cave art which depicts group hunting . by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers . it is likely that many tools made out of materials besides stone were prevalent but simply did not survive to the present day for scientists to observe . one exception is the neolithic “ ice man ” , found by two hikers in the ötztal alps , who was preserved in ice for 5,000 years ! he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures . without the aid of language , these things would likely have been impossible . examinations of the craniums of archaic homo sapiens suggest large brains with indentations that imply the development of brain areas associated with speech . exactly how humans developed a capacity for language is a matter of considerable debate . however , the historical record shows that language allowed for increasingly complex social structures , with an enhanced capacity for deliberation , morality , spirituality , and meaning-making . artwork such as cave painting and portable art demonstrates creativity and group structures as well . they show an interest in sharing knowledge , expressing feelings , and transmitting cultural information to later generations . though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic . such an object shows a desire to create beautiful figurines , but some also suggest that objects like this are tied to an interest in human fertility . what do you think ? what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ? what do you think was the purpose of paleolithic art such as cave paintings and figurines ?
they show an interest in sharing knowledge , expressing feelings , and transmitting cultural information to later generations . though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic .
how can they tell when the cave arts where painted in that era ?
overview paleolithic groups developed increasingly complex tools and objects made of stone and natural fibers . language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era . technological innovation stone tools are perhaps the first cultural artifacts which historians can use to reconstruct the worlds of paleolithic peoples . in fact , stone tools were so important in the paleolithic age that the names of paleolithic periods are based on the progression of tools : lower paleolithic , upper paleolithic , mesolithic ( middle stone age ) , and neolithic ( new stone age ) . $ ^1 $ stone tools also give us insight into the development of culture . anthropologists think paleolithic people likely hunted , foraged , and employed a communal system for dividing labor and resources . anthropologists have inferred this by drawing analogies to modern hunter-gatherer groups and by interpreting cave art which depicts group hunting . by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers . it is likely that many tools made out of materials besides stone were prevalent but simply did not survive to the present day for scientists to observe . one exception is the neolithic “ ice man ” , found by two hikers in the ötztal alps , who was preserved in ice for 5,000 years ! he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures . without the aid of language , these things would likely have been impossible . examinations of the craniums of archaic homo sapiens suggest large brains with indentations that imply the development of brain areas associated with speech . exactly how humans developed a capacity for language is a matter of considerable debate . however , the historical record shows that language allowed for increasingly complex social structures , with an enhanced capacity for deliberation , morality , spirituality , and meaning-making . artwork such as cave painting and portable art demonstrates creativity and group structures as well . they show an interest in sharing knowledge , expressing feelings , and transmitting cultural information to later generations . though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic . such an object shows a desire to create beautiful figurines , but some also suggest that objects like this are tied to an interest in human fertility . what do you think ? what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ? what do you think was the purpose of paleolithic art such as cave paintings and figurines ?
by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers .
i understand that there could be older needles that have n't been found but how would early humans have made clothes to fit their environments as they moved out of africa without needles ?
overview paleolithic groups developed increasingly complex tools and objects made of stone and natural fibers . language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era . technological innovation stone tools are perhaps the first cultural artifacts which historians can use to reconstruct the worlds of paleolithic peoples . in fact , stone tools were so important in the paleolithic age that the names of paleolithic periods are based on the progression of tools : lower paleolithic , upper paleolithic , mesolithic ( middle stone age ) , and neolithic ( new stone age ) . $ ^1 $ stone tools also give us insight into the development of culture . anthropologists think paleolithic people likely hunted , foraged , and employed a communal system for dividing labor and resources . anthropologists have inferred this by drawing analogies to modern hunter-gatherer groups and by interpreting cave art which depicts group hunting . by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers . it is likely that many tools made out of materials besides stone were prevalent but simply did not survive to the present day for scientists to observe . one exception is the neolithic “ ice man ” , found by two hikers in the ötztal alps , who was preserved in ice for 5,000 years ! he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures . without the aid of language , these things would likely have been impossible . examinations of the craniums of archaic homo sapiens suggest large brains with indentations that imply the development of brain areas associated with speech . exactly how humans developed a capacity for language is a matter of considerable debate . however , the historical record shows that language allowed for increasingly complex social structures , with an enhanced capacity for deliberation , morality , spirituality , and meaning-making . artwork such as cave painting and portable art demonstrates creativity and group structures as well . they show an interest in sharing knowledge , expressing feelings , and transmitting cultural information to later generations . though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic . such an object shows a desire to create beautiful figurines , but some also suggest that objects like this are tied to an interest in human fertility . what do you think ? what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ? what do you think was the purpose of paleolithic art such as cave paintings and figurines ?
what do you think ? what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ?
do we have any evidence of older artifacts being more detailed and advanced than the form in which they were discovered ?
overview paleolithic groups developed increasingly complex tools and objects made of stone and natural fibers . language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era . technological innovation stone tools are perhaps the first cultural artifacts which historians can use to reconstruct the worlds of paleolithic peoples . in fact , stone tools were so important in the paleolithic age that the names of paleolithic periods are based on the progression of tools : lower paleolithic , upper paleolithic , mesolithic ( middle stone age ) , and neolithic ( new stone age ) . $ ^1 $ stone tools also give us insight into the development of culture . anthropologists think paleolithic people likely hunted , foraged , and employed a communal system for dividing labor and resources . anthropologists have inferred this by drawing analogies to modern hunter-gatherer groups and by interpreting cave art which depicts group hunting . by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers . it is likely that many tools made out of materials besides stone were prevalent but simply did not survive to the present day for scientists to observe . one exception is the neolithic “ ice man ” , found by two hikers in the ötztal alps , who was preserved in ice for 5,000 years ! he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures . without the aid of language , these things would likely have been impossible . examinations of the craniums of archaic homo sapiens suggest large brains with indentations that imply the development of brain areas associated with speech . exactly how humans developed a capacity for language is a matter of considerable debate . however , the historical record shows that language allowed for increasingly complex social structures , with an enhanced capacity for deliberation , morality , spirituality , and meaning-making . artwork such as cave painting and portable art demonstrates creativity and group structures as well . they show an interest in sharing knowledge , expressing feelings , and transmitting cultural information to later generations . though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic . such an object shows a desire to create beautiful figurines , but some also suggest that objects like this are tied to an interest in human fertility . what do you think ? what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ? what do you think was the purpose of paleolithic art such as cave paintings and figurines ?
he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures .
what is the most important innovation of the paleolithic era ?
overview paleolithic groups developed increasingly complex tools and objects made of stone and natural fibers . language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era . technological innovation stone tools are perhaps the first cultural artifacts which historians can use to reconstruct the worlds of paleolithic peoples . in fact , stone tools were so important in the paleolithic age that the names of paleolithic periods are based on the progression of tools : lower paleolithic , upper paleolithic , mesolithic ( middle stone age ) , and neolithic ( new stone age ) . $ ^1 $ stone tools also give us insight into the development of culture . anthropologists think paleolithic people likely hunted , foraged , and employed a communal system for dividing labor and resources . anthropologists have inferred this by drawing analogies to modern hunter-gatherer groups and by interpreting cave art which depicts group hunting . by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers . it is likely that many tools made out of materials besides stone were prevalent but simply did not survive to the present day for scientists to observe . one exception is the neolithic “ ice man ” , found by two hikers in the ötztal alps , who was preserved in ice for 5,000 years ! he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures . without the aid of language , these things would likely have been impossible . examinations of the craniums of archaic homo sapiens suggest large brains with indentations that imply the development of brain areas associated with speech . exactly how humans developed a capacity for language is a matter of considerable debate . however , the historical record shows that language allowed for increasingly complex social structures , with an enhanced capacity for deliberation , morality , spirituality , and meaning-making . artwork such as cave painting and portable art demonstrates creativity and group structures as well . they show an interest in sharing knowledge , expressing feelings , and transmitting cultural information to later generations . though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic . such an object shows a desire to create beautiful figurines , but some also suggest that objects like this are tied to an interest in human fertility . what do you think ? what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ? what do you think was the purpose of paleolithic art such as cave paintings and figurines ?
language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era . technological innovation stone tools are perhaps the first cultural artifacts which historians can use to reconstruct the worlds of paleolithic peoples . in fact , stone tools were so important in the paleolithic age that the names of paleolithic periods are based on the progression of tools : lower paleolithic , upper paleolithic , mesolithic ( middle stone age ) , and neolithic ( new stone age ) . $ ^1 $ stone tools also give us insight into the development of culture .
in the first paragraph , what stone tool was the most useful during this time ?
overview paleolithic groups developed increasingly complex tools and objects made of stone and natural fibers . language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era . technological innovation stone tools are perhaps the first cultural artifacts which historians can use to reconstruct the worlds of paleolithic peoples . in fact , stone tools were so important in the paleolithic age that the names of paleolithic periods are based on the progression of tools : lower paleolithic , upper paleolithic , mesolithic ( middle stone age ) , and neolithic ( new stone age ) . $ ^1 $ stone tools also give us insight into the development of culture . anthropologists think paleolithic people likely hunted , foraged , and employed a communal system for dividing labor and resources . anthropologists have inferred this by drawing analogies to modern hunter-gatherer groups and by interpreting cave art which depicts group hunting . by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers . it is likely that many tools made out of materials besides stone were prevalent but simply did not survive to the present day for scientists to observe . one exception is the neolithic “ ice man ” , found by two hikers in the ötztal alps , who was preserved in ice for 5,000 years ! he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures . without the aid of language , these things would likely have been impossible . examinations of the craniums of archaic homo sapiens suggest large brains with indentations that imply the development of brain areas associated with speech . exactly how humans developed a capacity for language is a matter of considerable debate . however , the historical record shows that language allowed for increasingly complex social structures , with an enhanced capacity for deliberation , morality , spirituality , and meaning-making . artwork such as cave painting and portable art demonstrates creativity and group structures as well . they show an interest in sharing knowledge , expressing feelings , and transmitting cultural information to later generations . though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic . such an object shows a desire to create beautiful figurines , but some also suggest that objects like this are tied to an interest in human fertility . what do you think ? what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ? what do you think was the purpose of paleolithic art such as cave paintings and figurines ?
what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ? what do you think was the purpose of paleolithic art such as cave paintings and figurines ?
can those people encipher the stories behind the cave paintings ?
overview paleolithic groups developed increasingly complex tools and objects made of stone and natural fibers . language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era . technological innovation stone tools are perhaps the first cultural artifacts which historians can use to reconstruct the worlds of paleolithic peoples . in fact , stone tools were so important in the paleolithic age that the names of paleolithic periods are based on the progression of tools : lower paleolithic , upper paleolithic , mesolithic ( middle stone age ) , and neolithic ( new stone age ) . $ ^1 $ stone tools also give us insight into the development of culture . anthropologists think paleolithic people likely hunted , foraged , and employed a communal system for dividing labor and resources . anthropologists have inferred this by drawing analogies to modern hunter-gatherer groups and by interpreting cave art which depicts group hunting . by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers . it is likely that many tools made out of materials besides stone were prevalent but simply did not survive to the present day for scientists to observe . one exception is the neolithic “ ice man ” , found by two hikers in the ötztal alps , who was preserved in ice for 5,000 years ! he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures . without the aid of language , these things would likely have been impossible . examinations of the craniums of archaic homo sapiens suggest large brains with indentations that imply the development of brain areas associated with speech . exactly how humans developed a capacity for language is a matter of considerable debate . however , the historical record shows that language allowed for increasingly complex social structures , with an enhanced capacity for deliberation , morality , spirituality , and meaning-making . artwork such as cave painting and portable art demonstrates creativity and group structures as well . they show an interest in sharing knowledge , expressing feelings , and transmitting cultural information to later generations . though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic . such an object shows a desire to create beautiful figurines , but some also suggest that objects like this are tied to an interest in human fertility . what do you think ? what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ? what do you think was the purpose of paleolithic art such as cave paintings and figurines ?
by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers .
was the fertility figure the first religion ?
overview paleolithic groups developed increasingly complex tools and objects made of stone and natural fibers . language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era . technological innovation stone tools are perhaps the first cultural artifacts which historians can use to reconstruct the worlds of paleolithic peoples . in fact , stone tools were so important in the paleolithic age that the names of paleolithic periods are based on the progression of tools : lower paleolithic , upper paleolithic , mesolithic ( middle stone age ) , and neolithic ( new stone age ) . $ ^1 $ stone tools also give us insight into the development of culture . anthropologists think paleolithic people likely hunted , foraged , and employed a communal system for dividing labor and resources . anthropologists have inferred this by drawing analogies to modern hunter-gatherer groups and by interpreting cave art which depicts group hunting . by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers . it is likely that many tools made out of materials besides stone were prevalent but simply did not survive to the present day for scientists to observe . one exception is the neolithic “ ice man ” , found by two hikers in the ötztal alps , who was preserved in ice for 5,000 years ! he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures . without the aid of language , these things would likely have been impossible . examinations of the craniums of archaic homo sapiens suggest large brains with indentations that imply the development of brain areas associated with speech . exactly how humans developed a capacity for language is a matter of considerable debate . however , the historical record shows that language allowed for increasingly complex social structures , with an enhanced capacity for deliberation , morality , spirituality , and meaning-making . artwork such as cave painting and portable art demonstrates creativity and group structures as well . they show an interest in sharing knowledge , expressing feelings , and transmitting cultural information to later generations . though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic . such an object shows a desire to create beautiful figurines , but some also suggest that objects like this are tied to an interest in human fertility . what do you think ? what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ? what do you think was the purpose of paleolithic art such as cave paintings and figurines ?
overview paleolithic groups developed increasingly complex tools and objects made of stone and natural fibers . language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era .
if so , did the `` fatherly '' deity exist with this mother/earth goddess ?
overview paleolithic groups developed increasingly complex tools and objects made of stone and natural fibers . language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era . technological innovation stone tools are perhaps the first cultural artifacts which historians can use to reconstruct the worlds of paleolithic peoples . in fact , stone tools were so important in the paleolithic age that the names of paleolithic periods are based on the progression of tools : lower paleolithic , upper paleolithic , mesolithic ( middle stone age ) , and neolithic ( new stone age ) . $ ^1 $ stone tools also give us insight into the development of culture . anthropologists think paleolithic people likely hunted , foraged , and employed a communal system for dividing labor and resources . anthropologists have inferred this by drawing analogies to modern hunter-gatherer groups and by interpreting cave art which depicts group hunting . by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers . it is likely that many tools made out of materials besides stone were prevalent but simply did not survive to the present day for scientists to observe . one exception is the neolithic “ ice man ” , found by two hikers in the ötztal alps , who was preserved in ice for 5,000 years ! he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures . without the aid of language , these things would likely have been impossible . examinations of the craniums of archaic homo sapiens suggest large brains with indentations that imply the development of brain areas associated with speech . exactly how humans developed a capacity for language is a matter of considerable debate . however , the historical record shows that language allowed for increasingly complex social structures , with an enhanced capacity for deliberation , morality , spirituality , and meaning-making . artwork such as cave painting and portable art demonstrates creativity and group structures as well . they show an interest in sharing knowledge , expressing feelings , and transmitting cultural information to later generations . though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic . such an object shows a desire to create beautiful figurines , but some also suggest that objects like this are tied to an interest in human fertility . what do you think ? what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ? what do you think was the purpose of paleolithic art such as cave paintings and figurines ?
it is likely that many tools made out of materials besides stone were prevalent but simply did not survive to the present day for scientists to observe . one exception is the neolithic “ ice man ” , found by two hikers in the ötztal alps , who was preserved in ice for 5,000 years ! he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag .
how could the ice man be found with a copper ax ?
overview paleolithic groups developed increasingly complex tools and objects made of stone and natural fibers . language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era . technological innovation stone tools are perhaps the first cultural artifacts which historians can use to reconstruct the worlds of paleolithic peoples . in fact , stone tools were so important in the paleolithic age that the names of paleolithic periods are based on the progression of tools : lower paleolithic , upper paleolithic , mesolithic ( middle stone age ) , and neolithic ( new stone age ) . $ ^1 $ stone tools also give us insight into the development of culture . anthropologists think paleolithic people likely hunted , foraged , and employed a communal system for dividing labor and resources . anthropologists have inferred this by drawing analogies to modern hunter-gatherer groups and by interpreting cave art which depicts group hunting . by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers . it is likely that many tools made out of materials besides stone were prevalent but simply did not survive to the present day for scientists to observe . one exception is the neolithic “ ice man ” , found by two hikers in the ötztal alps , who was preserved in ice for 5,000 years ! he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures . without the aid of language , these things would likely have been impossible . examinations of the craniums of archaic homo sapiens suggest large brains with indentations that imply the development of brain areas associated with speech . exactly how humans developed a capacity for language is a matter of considerable debate . however , the historical record shows that language allowed for increasingly complex social structures , with an enhanced capacity for deliberation , morality , spirituality , and meaning-making . artwork such as cave painting and portable art demonstrates creativity and group structures as well . they show an interest in sharing knowledge , expressing feelings , and transmitting cultural information to later generations . though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic . such an object shows a desire to create beautiful figurines , but some also suggest that objects like this are tied to an interest in human fertility . what do you think ? what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ? what do you think was the purpose of paleolithic art such as cave paintings and figurines ?
though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic .
i wonder if these artists had art as an occupation in the hierarchy of paleolithic societies ?
overview paleolithic groups developed increasingly complex tools and objects made of stone and natural fibers . language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era . technological innovation stone tools are perhaps the first cultural artifacts which historians can use to reconstruct the worlds of paleolithic peoples . in fact , stone tools were so important in the paleolithic age that the names of paleolithic periods are based on the progression of tools : lower paleolithic , upper paleolithic , mesolithic ( middle stone age ) , and neolithic ( new stone age ) . $ ^1 $ stone tools also give us insight into the development of culture . anthropologists think paleolithic people likely hunted , foraged , and employed a communal system for dividing labor and resources . anthropologists have inferred this by drawing analogies to modern hunter-gatherer groups and by interpreting cave art which depicts group hunting . by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers . it is likely that many tools made out of materials besides stone were prevalent but simply did not survive to the present day for scientists to observe . one exception is the neolithic “ ice man ” , found by two hikers in the ötztal alps , who was preserved in ice for 5,000 years ! he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures . without the aid of language , these things would likely have been impossible . examinations of the craniums of archaic homo sapiens suggest large brains with indentations that imply the development of brain areas associated with speech . exactly how humans developed a capacity for language is a matter of considerable debate . however , the historical record shows that language allowed for increasingly complex social structures , with an enhanced capacity for deliberation , morality , spirituality , and meaning-making . artwork such as cave painting and portable art demonstrates creativity and group structures as well . they show an interest in sharing knowledge , expressing feelings , and transmitting cultural information to later generations . though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic . such an object shows a desire to create beautiful figurines , but some also suggest that objects like this are tied to an interest in human fertility . what do you think ? what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ? what do you think was the purpose of paleolithic art such as cave paintings and figurines ?
language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures . without the aid of language , these things would likely have been impossible .
did the early humans have religion ?
overview paleolithic groups developed increasingly complex tools and objects made of stone and natural fibers . language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era . technological innovation stone tools are perhaps the first cultural artifacts which historians can use to reconstruct the worlds of paleolithic peoples . in fact , stone tools were so important in the paleolithic age that the names of paleolithic periods are based on the progression of tools : lower paleolithic , upper paleolithic , mesolithic ( middle stone age ) , and neolithic ( new stone age ) . $ ^1 $ stone tools also give us insight into the development of culture . anthropologists think paleolithic people likely hunted , foraged , and employed a communal system for dividing labor and resources . anthropologists have inferred this by drawing analogies to modern hunter-gatherer groups and by interpreting cave art which depicts group hunting . by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers . it is likely that many tools made out of materials besides stone were prevalent but simply did not survive to the present day for scientists to observe . one exception is the neolithic “ ice man ” , found by two hikers in the ötztal alps , who was preserved in ice for 5,000 years ! he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures . without the aid of language , these things would likely have been impossible . examinations of the craniums of archaic homo sapiens suggest large brains with indentations that imply the development of brain areas associated with speech . exactly how humans developed a capacity for language is a matter of considerable debate . however , the historical record shows that language allowed for increasingly complex social structures , with an enhanced capacity for deliberation , morality , spirituality , and meaning-making . artwork such as cave painting and portable art demonstrates creativity and group structures as well . they show an interest in sharing knowledge , expressing feelings , and transmitting cultural information to later generations . though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic . such an object shows a desire to create beautiful figurines , but some also suggest that objects like this are tied to an interest in human fertility . what do you think ? what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ? what do you think was the purpose of paleolithic art such as cave paintings and figurines ?
without the aid of language , these things would likely have been impossible . examinations of the craniums of archaic homo sapiens suggest large brains with indentations that imply the development of brain areas associated with speech . exactly how humans developed a capacity for language is a matter of considerable debate .
could humans , being homo sapiens sapiens , reproduce with denisovan or neanderthal subspecies ?
overview paleolithic groups developed increasingly complex tools and objects made of stone and natural fibers . language , art , scientific inquiry , and spiritual life were some of the most important innovations of the paleolithic era . technological innovation stone tools are perhaps the first cultural artifacts which historians can use to reconstruct the worlds of paleolithic peoples . in fact , stone tools were so important in the paleolithic age that the names of paleolithic periods are based on the progression of tools : lower paleolithic , upper paleolithic , mesolithic ( middle stone age ) , and neolithic ( new stone age ) . $ ^1 $ stone tools also give us insight into the development of culture . anthropologists think paleolithic people likely hunted , foraged , and employed a communal system for dividing labor and resources . anthropologists have inferred this by drawing analogies to modern hunter-gatherer groups and by interpreting cave art which depicts group hunting . by approximately 40,000 years ago , narrow stone blades and tools made of bone , ivory , and antler appeared , along with simple wood instruments . closer to 20,000 years ago , the first known needles were produced . eventually , between 17,000 and 8,000 years ago , humans produced more complicated instruments like barbed harpoons and spear-throwers . it is likely that many tools made out of materials besides stone were prevalent but simply did not survive to the present day for scientists to observe . one exception is the neolithic “ ice man ” , found by two hikers in the ötztal alps , who was preserved in ice for 5,000 years ! he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures . without the aid of language , these things would likely have been impossible . examinations of the craniums of archaic homo sapiens suggest large brains with indentations that imply the development of brain areas associated with speech . exactly how humans developed a capacity for language is a matter of considerable debate . however , the historical record shows that language allowed for increasingly complex social structures , with an enhanced capacity for deliberation , morality , spirituality , and meaning-making . artwork such as cave painting and portable art demonstrates creativity and group structures as well . they show an interest in sharing knowledge , expressing feelings , and transmitting cultural information to later generations . though artwork from over 35,000 years ago is rare , there is ample evidence of cave paintings and statuettes from later periods . in addition to cave art , portable figurines dated to paleolithic times have been found . many of these include finely carved facial features , while others accentuate sexual organs and buttocks , such as the 25,000 year old figurine found at dolni vestonice in the modern-day czech republic . such an object shows a desire to create beautiful figurines , but some also suggest that objects like this are tied to an interest in human fertility . what do you think ? what evidence do we have that paleolithic people had developed a capacity for language ? could paleolithic people have survived in the ways that they did without language ? what do you think was the purpose of paleolithic art such as cave paintings and figurines ?
he was found with a robust set of stone and natural-fiber tools , including a six-foot longbow , deerskin case , fourteen arrows , a stick with an antler tip for sharpening flint blades , a small flint dagger in a woven sheath , a copper axe , and a medicine bag . language , culture and art language was perhaps the most important innovation of the paleolithic era . scientists can infer the early use of language from the fact that humans traversed large swaths of land , established settlements , created tools , traded , and instituted social hierarchies and cultures .
what language did the paleolithic humans speak ?
before we can create an entire particlesystem , we have to create an object that will describe a single particle . the good news : we 've done this already . our mover object from the forces section serves as the perfect template . for us , a particle is an independent body that moves about the screen . it has location , velocity , and acceleration , a constructor to initialize those variables , and functions to display ( ) itself and update ( ) its location . `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; } ; particle.prototype.display = function ( ) { stroke ( 0 , 0 , 0 ) ; fill ( 175 , 175 , 175 ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` this is about as simple as a particle can get . from here , we could take our particle in several directions . we could add an applyforce ( ) method to affect the particle ’ s behavior ( we ’ ll do precisely this in a future example ) . we could add variables to describe color and shape , or use image ( ) to draw the particle . for now , however , let ’ s focus on adding just one additional detail : lifespan . typical particle systems involve something called an emitter . the emitter is the source of the particles and controls the initial settings for the particles , location , velocity , etc . an emitter might emit a single burst of particles , or a continuous stream of particles , or both . the point is that for a typical implementation such as this , a particle is born at the emitter but does not live forever . if it were to live forever , our program would eventually grind to a halt as the number of particles increased to an unwieldy number over time . as new particles are born , we need old particles to die . this creates the illusion of an infinite stream of particles , and the performance of our program does not suffer . there are many different ways to decide when a particle dies . for example , it could come into contact with another object , or it could simply leave the screen . for our first particle object , however , we ’ re simply going to add a timetolive property . it will act as a timer , counting down from 255 to 0 , at which point we 'll consider the particle to be `` dead . '' and so we expand the particle object as follows : `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; this.timetolive = 255 ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; this.timetolive -= 2 ; } ; particle.prototype.display = function ( ) { stroke ( 255 , 255 , 255 , this.timetolive ) ; fill ( 127 , 127 , 127 , this.timetolive ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` the reason we chose to start the timetolive at 255 and count down to 0 is for convenience . with those values , we can use timetolive as the alpha transparency for the ellipse as well . when the particle is “ dead ” it will also have faded away onscreen . with the addition of the timetolive property , we ’ ll also need one additional method—a function that can be queried ( for a true or false answer ) as to whether the particle is alive or dead . this will come in handy when we are writing the particlesystem object , whose task will be to manage the list of particles themselves . writing this function is pretty easy ; we just need to check and see if the value of timetolive is less than 0 . if it is we return true , if not we return false . particle.prototype.isdead = function ( ) { if ( this.timetolive & lt ; 0 ) { return true ; } else { return false ; } } ; before we get to the next step of making many particles , it ’ s worth taking a moment to make sure our particle works correctly and create a sketch with one single particle object . here is the full code below , with two small additions . we add a convenience method called run ( ) that simply calls both update ( ) and display ( ) for us . in addition , we give the particle a random initial velocity as well as a downward acceleration ( to simulate gravity ) . now that we have an object to describe a single particle , we ’ re ready for the next big step . how do we keep track of many particles , when we can ’ t ensure exactly how many particles we might have at any given time ?
writing this function is pretty easy ; we just need to check and see if the value of timetolive is less than 0 . if it is we return true , if not we return false . particle.prototype.isdead = function ( ) { if ( this.timetolive & lt ; 0 ) { return true ; } else { return false ; } } ; before we get to the next step of making many particles , it ’ s worth taking a moment to make sure our particle works correctly and create a sketch with one single particle object .
what does `` return '' do ?
before we can create an entire particlesystem , we have to create an object that will describe a single particle . the good news : we 've done this already . our mover object from the forces section serves as the perfect template . for us , a particle is an independent body that moves about the screen . it has location , velocity , and acceleration , a constructor to initialize those variables , and functions to display ( ) itself and update ( ) its location . `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; } ; particle.prototype.display = function ( ) { stroke ( 0 , 0 , 0 ) ; fill ( 175 , 175 , 175 ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` this is about as simple as a particle can get . from here , we could take our particle in several directions . we could add an applyforce ( ) method to affect the particle ’ s behavior ( we ’ ll do precisely this in a future example ) . we could add variables to describe color and shape , or use image ( ) to draw the particle . for now , however , let ’ s focus on adding just one additional detail : lifespan . typical particle systems involve something called an emitter . the emitter is the source of the particles and controls the initial settings for the particles , location , velocity , etc . an emitter might emit a single burst of particles , or a continuous stream of particles , or both . the point is that for a typical implementation such as this , a particle is born at the emitter but does not live forever . if it were to live forever , our program would eventually grind to a halt as the number of particles increased to an unwieldy number over time . as new particles are born , we need old particles to die . this creates the illusion of an infinite stream of particles , and the performance of our program does not suffer . there are many different ways to decide when a particle dies . for example , it could come into contact with another object , or it could simply leave the screen . for our first particle object , however , we ’ re simply going to add a timetolive property . it will act as a timer , counting down from 255 to 0 , at which point we 'll consider the particle to be `` dead . '' and so we expand the particle object as follows : `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; this.timetolive = 255 ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; this.timetolive -= 2 ; } ; particle.prototype.display = function ( ) { stroke ( 255 , 255 , 255 , this.timetolive ) ; fill ( 127 , 127 , 127 , this.timetolive ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` the reason we chose to start the timetolive at 255 and count down to 0 is for convenience . with those values , we can use timetolive as the alpha transparency for the ellipse as well . when the particle is “ dead ” it will also have faded away onscreen . with the addition of the timetolive property , we ’ ll also need one additional method—a function that can be queried ( for a true or false answer ) as to whether the particle is alive or dead . this will come in handy when we are writing the particlesystem object , whose task will be to manage the list of particles themselves . writing this function is pretty easy ; we just need to check and see if the value of timetolive is less than 0 . if it is we return true , if not we return false . particle.prototype.isdead = function ( ) { if ( this.timetolive & lt ; 0 ) { return true ; } else { return false ; } } ; before we get to the next step of making many particles , it ’ s worth taking a moment to make sure our particle works correctly and create a sketch with one single particle object . here is the full code below , with two small additions . we add a convenience method called run ( ) that simply calls both update ( ) and display ( ) for us . in addition , we give the particle a random initial velocity as well as a downward acceleration ( to simulate gravity ) . now that we have an object to describe a single particle , we ’ re ready for the next big step . how do we keep track of many particles , when we can ’ t ensure exactly how many particles we might have at any given time ?
in addition , we give the particle a random initial velocity as well as a downward acceleration ( to simulate gravity ) . now that we have an object to describe a single particle , we ’ re ready for the next big step . how do we keep track of many particles , when we can ’ t ensure exactly how many particles we might have at any given time ?
how to stop rotation on next challenge ?
before we can create an entire particlesystem , we have to create an object that will describe a single particle . the good news : we 've done this already . our mover object from the forces section serves as the perfect template . for us , a particle is an independent body that moves about the screen . it has location , velocity , and acceleration , a constructor to initialize those variables , and functions to display ( ) itself and update ( ) its location . `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; } ; particle.prototype.display = function ( ) { stroke ( 0 , 0 , 0 ) ; fill ( 175 , 175 , 175 ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` this is about as simple as a particle can get . from here , we could take our particle in several directions . we could add an applyforce ( ) method to affect the particle ’ s behavior ( we ’ ll do precisely this in a future example ) . we could add variables to describe color and shape , or use image ( ) to draw the particle . for now , however , let ’ s focus on adding just one additional detail : lifespan . typical particle systems involve something called an emitter . the emitter is the source of the particles and controls the initial settings for the particles , location , velocity , etc . an emitter might emit a single burst of particles , or a continuous stream of particles , or both . the point is that for a typical implementation such as this , a particle is born at the emitter but does not live forever . if it were to live forever , our program would eventually grind to a halt as the number of particles increased to an unwieldy number over time . as new particles are born , we need old particles to die . this creates the illusion of an infinite stream of particles , and the performance of our program does not suffer . there are many different ways to decide when a particle dies . for example , it could come into contact with another object , or it could simply leave the screen . for our first particle object , however , we ’ re simply going to add a timetolive property . it will act as a timer , counting down from 255 to 0 , at which point we 'll consider the particle to be `` dead . '' and so we expand the particle object as follows : `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; this.timetolive = 255 ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; this.timetolive -= 2 ; } ; particle.prototype.display = function ( ) { stroke ( 255 , 255 , 255 , this.timetolive ) ; fill ( 127 , 127 , 127 , this.timetolive ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` the reason we chose to start the timetolive at 255 and count down to 0 is for convenience . with those values , we can use timetolive as the alpha transparency for the ellipse as well . when the particle is “ dead ” it will also have faded away onscreen . with the addition of the timetolive property , we ’ ll also need one additional method—a function that can be queried ( for a true or false answer ) as to whether the particle is alive or dead . this will come in handy when we are writing the particlesystem object , whose task will be to manage the list of particles themselves . writing this function is pretty easy ; we just need to check and see if the value of timetolive is less than 0 . if it is we return true , if not we return false . particle.prototype.isdead = function ( ) { if ( this.timetolive & lt ; 0 ) { return true ; } else { return false ; } } ; before we get to the next step of making many particles , it ’ s worth taking a moment to make sure our particle works correctly and create a sketch with one single particle object . here is the full code below , with two small additions . we add a convenience method called run ( ) that simply calls both update ( ) and display ( ) for us . in addition , we give the particle a random initial velocity as well as a downward acceleration ( to simulate gravity ) . now that we have an object to describe a single particle , we ’ re ready for the next big step . how do we keep track of many particles , when we can ’ t ensure exactly how many particles we might have at any given time ?
if it is we return true , if not we return false . particle.prototype.isdead = function ( ) { if ( this.timetolive & lt ; 0 ) { return true ; } else { return false ; } } ; before we get to the next step of making many particles , it ’ s worth taking a moment to make sure our particle works correctly and create a sketch with one single particle object . here is the full code below , with two small additions .
why cant the particle.prototype.isdead function just return a boolean value , like this , particle.prototype.isdead = function ( ) { return this.timetolive < = 0 ; } instead of having a series of uneeded if statements ?
before we can create an entire particlesystem , we have to create an object that will describe a single particle . the good news : we 've done this already . our mover object from the forces section serves as the perfect template . for us , a particle is an independent body that moves about the screen . it has location , velocity , and acceleration , a constructor to initialize those variables , and functions to display ( ) itself and update ( ) its location . `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; } ; particle.prototype.display = function ( ) { stroke ( 0 , 0 , 0 ) ; fill ( 175 , 175 , 175 ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` this is about as simple as a particle can get . from here , we could take our particle in several directions . we could add an applyforce ( ) method to affect the particle ’ s behavior ( we ’ ll do precisely this in a future example ) . we could add variables to describe color and shape , or use image ( ) to draw the particle . for now , however , let ’ s focus on adding just one additional detail : lifespan . typical particle systems involve something called an emitter . the emitter is the source of the particles and controls the initial settings for the particles , location , velocity , etc . an emitter might emit a single burst of particles , or a continuous stream of particles , or both . the point is that for a typical implementation such as this , a particle is born at the emitter but does not live forever . if it were to live forever , our program would eventually grind to a halt as the number of particles increased to an unwieldy number over time . as new particles are born , we need old particles to die . this creates the illusion of an infinite stream of particles , and the performance of our program does not suffer . there are many different ways to decide when a particle dies . for example , it could come into contact with another object , or it could simply leave the screen . for our first particle object , however , we ’ re simply going to add a timetolive property . it will act as a timer , counting down from 255 to 0 , at which point we 'll consider the particle to be `` dead . '' and so we expand the particle object as follows : `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; this.timetolive = 255 ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; this.timetolive -= 2 ; } ; particle.prototype.display = function ( ) { stroke ( 255 , 255 , 255 , this.timetolive ) ; fill ( 127 , 127 , 127 , this.timetolive ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` the reason we chose to start the timetolive at 255 and count down to 0 is for convenience . with those values , we can use timetolive as the alpha transparency for the ellipse as well . when the particle is “ dead ” it will also have faded away onscreen . with the addition of the timetolive property , we ’ ll also need one additional method—a function that can be queried ( for a true or false answer ) as to whether the particle is alive or dead . this will come in handy when we are writing the particlesystem object , whose task will be to manage the list of particles themselves . writing this function is pretty easy ; we just need to check and see if the value of timetolive is less than 0 . if it is we return true , if not we return false . particle.prototype.isdead = function ( ) { if ( this.timetolive & lt ; 0 ) { return true ; } else { return false ; } } ; before we get to the next step of making many particles , it ’ s worth taking a moment to make sure our particle works correctly and create a sketch with one single particle object . here is the full code below , with two small additions . we add a convenience method called run ( ) that simply calls both update ( ) and display ( ) for us . in addition , we give the particle a random initial velocity as well as a downward acceleration ( to simulate gravity ) . now that we have an object to describe a single particle , we ’ re ready for the next big step . how do we keep track of many particles , when we can ’ t ensure exactly how many particles we might have at any given time ?
here is the full code below , with two small additions . we add a convenience method called run ( ) that simply calls both update ( ) and display ( ) for us . in addition , we give the particle a random initial velocity as well as a downward acceleration ( to simulate gravity ) .
what 's the difference between .display ( ) ; and .draw ( ) ; ?
before we can create an entire particlesystem , we have to create an object that will describe a single particle . the good news : we 've done this already . our mover object from the forces section serves as the perfect template . for us , a particle is an independent body that moves about the screen . it has location , velocity , and acceleration , a constructor to initialize those variables , and functions to display ( ) itself and update ( ) its location . `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; } ; particle.prototype.display = function ( ) { stroke ( 0 , 0 , 0 ) ; fill ( 175 , 175 , 175 ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` this is about as simple as a particle can get . from here , we could take our particle in several directions . we could add an applyforce ( ) method to affect the particle ’ s behavior ( we ’ ll do precisely this in a future example ) . we could add variables to describe color and shape , or use image ( ) to draw the particle . for now , however , let ’ s focus on adding just one additional detail : lifespan . typical particle systems involve something called an emitter . the emitter is the source of the particles and controls the initial settings for the particles , location , velocity , etc . an emitter might emit a single burst of particles , or a continuous stream of particles , or both . the point is that for a typical implementation such as this , a particle is born at the emitter but does not live forever . if it were to live forever , our program would eventually grind to a halt as the number of particles increased to an unwieldy number over time . as new particles are born , we need old particles to die . this creates the illusion of an infinite stream of particles , and the performance of our program does not suffer . there are many different ways to decide when a particle dies . for example , it could come into contact with another object , or it could simply leave the screen . for our first particle object , however , we ’ re simply going to add a timetolive property . it will act as a timer , counting down from 255 to 0 , at which point we 'll consider the particle to be `` dead . '' and so we expand the particle object as follows : `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; this.timetolive = 255 ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; this.timetolive -= 2 ; } ; particle.prototype.display = function ( ) { stroke ( 255 , 255 , 255 , this.timetolive ) ; fill ( 127 , 127 , 127 , this.timetolive ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` the reason we chose to start the timetolive at 255 and count down to 0 is for convenience . with those values , we can use timetolive as the alpha transparency for the ellipse as well . when the particle is “ dead ” it will also have faded away onscreen . with the addition of the timetolive property , we ’ ll also need one additional method—a function that can be queried ( for a true or false answer ) as to whether the particle is alive or dead . this will come in handy when we are writing the particlesystem object , whose task will be to manage the list of particles themselves . writing this function is pretty easy ; we just need to check and see if the value of timetolive is less than 0 . if it is we return true , if not we return false . particle.prototype.isdead = function ( ) { if ( this.timetolive & lt ; 0 ) { return true ; } else { return false ; } } ; before we get to the next step of making many particles , it ’ s worth taking a moment to make sure our particle works correctly and create a sketch with one single particle object . here is the full code below , with two small additions . we add a convenience method called run ( ) that simply calls both update ( ) and display ( ) for us . in addition , we give the particle a random initial velocity as well as a downward acceleration ( to simulate gravity ) . now that we have an object to describe a single particle , we ’ re ready for the next big step . how do we keep track of many particles , when we can ’ t ensure exactly how many particles we might have at any given time ?
it has location , velocity , and acceleration , a constructor to initialize those variables , and functions to display ( ) itself and update ( ) its location . `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; } ; particle.prototype.display = function ( ) { stroke ( 0 , 0 , 0 ) ; fill ( 175 , 175 , 175 ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` this is about as simple as a particle can get . from here , we could take our particle in several directions .
in the challenge 'falling leaves ' what does var self = this means ?
before we can create an entire particlesystem , we have to create an object that will describe a single particle . the good news : we 've done this already . our mover object from the forces section serves as the perfect template . for us , a particle is an independent body that moves about the screen . it has location , velocity , and acceleration , a constructor to initialize those variables , and functions to display ( ) itself and update ( ) its location . `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; } ; particle.prototype.display = function ( ) { stroke ( 0 , 0 , 0 ) ; fill ( 175 , 175 , 175 ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` this is about as simple as a particle can get . from here , we could take our particle in several directions . we could add an applyforce ( ) method to affect the particle ’ s behavior ( we ’ ll do precisely this in a future example ) . we could add variables to describe color and shape , or use image ( ) to draw the particle . for now , however , let ’ s focus on adding just one additional detail : lifespan . typical particle systems involve something called an emitter . the emitter is the source of the particles and controls the initial settings for the particles , location , velocity , etc . an emitter might emit a single burst of particles , or a continuous stream of particles , or both . the point is that for a typical implementation such as this , a particle is born at the emitter but does not live forever . if it were to live forever , our program would eventually grind to a halt as the number of particles increased to an unwieldy number over time . as new particles are born , we need old particles to die . this creates the illusion of an infinite stream of particles , and the performance of our program does not suffer . there are many different ways to decide when a particle dies . for example , it could come into contact with another object , or it could simply leave the screen . for our first particle object , however , we ’ re simply going to add a timetolive property . it will act as a timer , counting down from 255 to 0 , at which point we 'll consider the particle to be `` dead . '' and so we expand the particle object as follows : `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; this.timetolive = 255 ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; this.timetolive -= 2 ; } ; particle.prototype.display = function ( ) { stroke ( 255 , 255 , 255 , this.timetolive ) ; fill ( 127 , 127 , 127 , this.timetolive ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` the reason we chose to start the timetolive at 255 and count down to 0 is for convenience . with those values , we can use timetolive as the alpha transparency for the ellipse as well . when the particle is “ dead ” it will also have faded away onscreen . with the addition of the timetolive property , we ’ ll also need one additional method—a function that can be queried ( for a true or false answer ) as to whether the particle is alive or dead . this will come in handy when we are writing the particlesystem object , whose task will be to manage the list of particles themselves . writing this function is pretty easy ; we just need to check and see if the value of timetolive is less than 0 . if it is we return true , if not we return false . particle.prototype.isdead = function ( ) { if ( this.timetolive & lt ; 0 ) { return true ; } else { return false ; } } ; before we get to the next step of making many particles , it ’ s worth taking a moment to make sure our particle works correctly and create a sketch with one single particle object . here is the full code below , with two small additions . we add a convenience method called run ( ) that simply calls both update ( ) and display ( ) for us . in addition , we give the particle a random initial velocity as well as a downward acceleration ( to simulate gravity ) . now that we have an object to describe a single particle , we ’ re ready for the next big step . how do we keep track of many particles , when we can ’ t ensure exactly how many particles we might have at any given time ?
before we can create an entire particlesystem , we have to create an object that will describe a single particle . the good news : we 've done this already .
what is p vector ( ) ; ?
before we can create an entire particlesystem , we have to create an object that will describe a single particle . the good news : we 've done this already . our mover object from the forces section serves as the perfect template . for us , a particle is an independent body that moves about the screen . it has location , velocity , and acceleration , a constructor to initialize those variables , and functions to display ( ) itself and update ( ) its location . `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; } ; particle.prototype.display = function ( ) { stroke ( 0 , 0 , 0 ) ; fill ( 175 , 175 , 175 ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` this is about as simple as a particle can get . from here , we could take our particle in several directions . we could add an applyforce ( ) method to affect the particle ’ s behavior ( we ’ ll do precisely this in a future example ) . we could add variables to describe color and shape , or use image ( ) to draw the particle . for now , however , let ’ s focus on adding just one additional detail : lifespan . typical particle systems involve something called an emitter . the emitter is the source of the particles and controls the initial settings for the particles , location , velocity , etc . an emitter might emit a single burst of particles , or a continuous stream of particles , or both . the point is that for a typical implementation such as this , a particle is born at the emitter but does not live forever . if it were to live forever , our program would eventually grind to a halt as the number of particles increased to an unwieldy number over time . as new particles are born , we need old particles to die . this creates the illusion of an infinite stream of particles , and the performance of our program does not suffer . there are many different ways to decide when a particle dies . for example , it could come into contact with another object , or it could simply leave the screen . for our first particle object , however , we ’ re simply going to add a timetolive property . it will act as a timer , counting down from 255 to 0 , at which point we 'll consider the particle to be `` dead . '' and so we expand the particle object as follows : `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; this.timetolive = 255 ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; this.timetolive -= 2 ; } ; particle.prototype.display = function ( ) { stroke ( 255 , 255 , 255 , this.timetolive ) ; fill ( 127 , 127 , 127 , this.timetolive ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` the reason we chose to start the timetolive at 255 and count down to 0 is for convenience . with those values , we can use timetolive as the alpha transparency for the ellipse as well . when the particle is “ dead ” it will also have faded away onscreen . with the addition of the timetolive property , we ’ ll also need one additional method—a function that can be queried ( for a true or false answer ) as to whether the particle is alive or dead . this will come in handy when we are writing the particlesystem object , whose task will be to manage the list of particles themselves . writing this function is pretty easy ; we just need to check and see if the value of timetolive is less than 0 . if it is we return true , if not we return false . particle.prototype.isdead = function ( ) { if ( this.timetolive & lt ; 0 ) { return true ; } else { return false ; } } ; before we get to the next step of making many particles , it ’ s worth taking a moment to make sure our particle works correctly and create a sketch with one single particle object . here is the full code below , with two small additions . we add a convenience method called run ( ) that simply calls both update ( ) and display ( ) for us . in addition , we give the particle a random initial velocity as well as a downward acceleration ( to simulate gravity ) . now that we have an object to describe a single particle , we ’ re ready for the next big step . how do we keep track of many particles , when we can ’ t ensure exactly how many particles we might have at any given time ?
with those values , we can use timetolive as the alpha transparency for the ellipse as well . when the particle is “ dead ” it will also have faded away onscreen . with the addition of the timetolive property , we ’ ll also need one additional method—a function that can be queried ( for a true or false answer ) as to whether the particle is alive or dead .
is the particle object really dead ?
before we can create an entire particlesystem , we have to create an object that will describe a single particle . the good news : we 've done this already . our mover object from the forces section serves as the perfect template . for us , a particle is an independent body that moves about the screen . it has location , velocity , and acceleration , a constructor to initialize those variables , and functions to display ( ) itself and update ( ) its location . `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; } ; particle.prototype.display = function ( ) { stroke ( 0 , 0 , 0 ) ; fill ( 175 , 175 , 175 ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` this is about as simple as a particle can get . from here , we could take our particle in several directions . we could add an applyforce ( ) method to affect the particle ’ s behavior ( we ’ ll do precisely this in a future example ) . we could add variables to describe color and shape , or use image ( ) to draw the particle . for now , however , let ’ s focus on adding just one additional detail : lifespan . typical particle systems involve something called an emitter . the emitter is the source of the particles and controls the initial settings for the particles , location , velocity , etc . an emitter might emit a single burst of particles , or a continuous stream of particles , or both . the point is that for a typical implementation such as this , a particle is born at the emitter but does not live forever . if it were to live forever , our program would eventually grind to a halt as the number of particles increased to an unwieldy number over time . as new particles are born , we need old particles to die . this creates the illusion of an infinite stream of particles , and the performance of our program does not suffer . there are many different ways to decide when a particle dies . for example , it could come into contact with another object , or it could simply leave the screen . for our first particle object , however , we ’ re simply going to add a timetolive property . it will act as a timer , counting down from 255 to 0 , at which point we 'll consider the particle to be `` dead . '' and so we expand the particle object as follows : `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; this.timetolive = 255 ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; this.timetolive -= 2 ; } ; particle.prototype.display = function ( ) { stroke ( 255 , 255 , 255 , this.timetolive ) ; fill ( 127 , 127 , 127 , this.timetolive ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` the reason we chose to start the timetolive at 255 and count down to 0 is for convenience . with those values , we can use timetolive as the alpha transparency for the ellipse as well . when the particle is “ dead ” it will also have faded away onscreen . with the addition of the timetolive property , we ’ ll also need one additional method—a function that can be queried ( for a true or false answer ) as to whether the particle is alive or dead . this will come in handy when we are writing the particlesystem object , whose task will be to manage the list of particles themselves . writing this function is pretty easy ; we just need to check and see if the value of timetolive is less than 0 . if it is we return true , if not we return false . particle.prototype.isdead = function ( ) { if ( this.timetolive & lt ; 0 ) { return true ; } else { return false ; } } ; before we get to the next step of making many particles , it ’ s worth taking a moment to make sure our particle works correctly and create a sketch with one single particle object . here is the full code below , with two small additions . we add a convenience method called run ( ) that simply calls both update ( ) and display ( ) for us . in addition , we give the particle a random initial velocity as well as a downward acceleration ( to simulate gravity ) . now that we have an object to describe a single particle , we ’ re ready for the next big step . how do we keep track of many particles , when we can ’ t ensure exactly how many particles we might have at any given time ?
if it is we return true , if not we return false . particle.prototype.isdead = function ( ) { if ( this.timetolive & lt ; 0 ) { return true ; } else { return false ; } } ; before we get to the next step of making many particles , it ’ s worth taking a moment to make sure our particle works correctly and create a sketch with one single particle object . here is the full code below , with two small additions .
wo n't the code above create an ever increasing number of particle objects that still need to have their positions calculated and isdead status checked for every cycle ?
before we can create an entire particlesystem , we have to create an object that will describe a single particle . the good news : we 've done this already . our mover object from the forces section serves as the perfect template . for us , a particle is an independent body that moves about the screen . it has location , velocity , and acceleration , a constructor to initialize those variables , and functions to display ( ) itself and update ( ) its location . `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; } ; particle.prototype.display = function ( ) { stroke ( 0 , 0 , 0 ) ; fill ( 175 , 175 , 175 ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` this is about as simple as a particle can get . from here , we could take our particle in several directions . we could add an applyforce ( ) method to affect the particle ’ s behavior ( we ’ ll do precisely this in a future example ) . we could add variables to describe color and shape , or use image ( ) to draw the particle . for now , however , let ’ s focus on adding just one additional detail : lifespan . typical particle systems involve something called an emitter . the emitter is the source of the particles and controls the initial settings for the particles , location , velocity , etc . an emitter might emit a single burst of particles , or a continuous stream of particles , or both . the point is that for a typical implementation such as this , a particle is born at the emitter but does not live forever . if it were to live forever , our program would eventually grind to a halt as the number of particles increased to an unwieldy number over time . as new particles are born , we need old particles to die . this creates the illusion of an infinite stream of particles , and the performance of our program does not suffer . there are many different ways to decide when a particle dies . for example , it could come into contact with another object , or it could simply leave the screen . for our first particle object , however , we ’ re simply going to add a timetolive property . it will act as a timer , counting down from 255 to 0 , at which point we 'll consider the particle to be `` dead . '' and so we expand the particle object as follows : `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; this.timetolive = 255 ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; this.timetolive -= 2 ; } ; particle.prototype.display = function ( ) { stroke ( 255 , 255 , 255 , this.timetolive ) ; fill ( 127 , 127 , 127 , this.timetolive ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` the reason we chose to start the timetolive at 255 and count down to 0 is for convenience . with those values , we can use timetolive as the alpha transparency for the ellipse as well . when the particle is “ dead ” it will also have faded away onscreen . with the addition of the timetolive property , we ’ ll also need one additional method—a function that can be queried ( for a true or false answer ) as to whether the particle is alive or dead . this will come in handy when we are writing the particlesystem object , whose task will be to manage the list of particles themselves . writing this function is pretty easy ; we just need to check and see if the value of timetolive is less than 0 . if it is we return true , if not we return false . particle.prototype.isdead = function ( ) { if ( this.timetolive & lt ; 0 ) { return true ; } else { return false ; } } ; before we get to the next step of making many particles , it ’ s worth taking a moment to make sure our particle works correctly and create a sketch with one single particle object . here is the full code below , with two small additions . we add a convenience method called run ( ) that simply calls both update ( ) and display ( ) for us . in addition , we give the particle a random initial velocity as well as a downward acceleration ( to simulate gravity ) . now that we have an object to describe a single particle , we ’ re ready for the next big step . how do we keep track of many particles , when we can ’ t ensure exactly how many particles we might have at any given time ?
it has location , velocity , and acceleration , a constructor to initialize those variables , and functions to display ( ) itself and update ( ) its location . `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; } ; particle.prototype.display = function ( ) { stroke ( 0 , 0 , 0 ) ; fill ( 175 , 175 , 175 ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` this is about as simple as a particle can get . from here , we could take our particle in several directions .
ok , here is my code again ; var leaves = [ ] ; var tree = new tree ( new pvector ( width/2 , 400 ) ) ; mouseclicked = function ( ) { leaves.push ( new particle ( new pvector ( mousex , mousey ) ) ) ; } ; draw = function ( ) { background ( 194 , 231 , 255 ) ; tree.display ( ) ; for ( var i = 0 ; i < leaves.length ; i++ ) { leaves [ i ] .run ( ) ; } } ; i did that , still wo n't let me pass , it gives me a message ; ( make a leaf variable in your for loop , save leaves [ i ] to it , and reference it to leaves ) , what should i do next ?
before we can create an entire particlesystem , we have to create an object that will describe a single particle . the good news : we 've done this already . our mover object from the forces section serves as the perfect template . for us , a particle is an independent body that moves about the screen . it has location , velocity , and acceleration , a constructor to initialize those variables , and functions to display ( ) itself and update ( ) its location . `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; } ; particle.prototype.display = function ( ) { stroke ( 0 , 0 , 0 ) ; fill ( 175 , 175 , 175 ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` this is about as simple as a particle can get . from here , we could take our particle in several directions . we could add an applyforce ( ) method to affect the particle ’ s behavior ( we ’ ll do precisely this in a future example ) . we could add variables to describe color and shape , or use image ( ) to draw the particle . for now , however , let ’ s focus on adding just one additional detail : lifespan . typical particle systems involve something called an emitter . the emitter is the source of the particles and controls the initial settings for the particles , location , velocity , etc . an emitter might emit a single burst of particles , or a continuous stream of particles , or both . the point is that for a typical implementation such as this , a particle is born at the emitter but does not live forever . if it were to live forever , our program would eventually grind to a halt as the number of particles increased to an unwieldy number over time . as new particles are born , we need old particles to die . this creates the illusion of an infinite stream of particles , and the performance of our program does not suffer . there are many different ways to decide when a particle dies . for example , it could come into contact with another object , or it could simply leave the screen . for our first particle object , however , we ’ re simply going to add a timetolive property . it will act as a timer , counting down from 255 to 0 , at which point we 'll consider the particle to be `` dead . '' and so we expand the particle object as follows : `` ` // a simple particle object var particle = function ( position ) { this.acceleration = new pvector ( ) ; this.velocity = new pvector ( ) ; this.position = position.get ( ) ; this.timetolive = 255 ; } ; particle.prototype.update = function ( ) { this.velocity.add ( this.acceleration ) ; this.position.add ( this.velocity ) ; this.timetolive -= 2 ; } ; particle.prototype.display = function ( ) { stroke ( 255 , 255 , 255 , this.timetolive ) ; fill ( 127 , 127 , 127 , this.timetolive ) ; ellipse ( this.position.x , this.position.y , 8 , 8 ) ; } ; `` ` the reason we chose to start the timetolive at 255 and count down to 0 is for convenience . with those values , we can use timetolive as the alpha transparency for the ellipse as well . when the particle is “ dead ” it will also have faded away onscreen . with the addition of the timetolive property , we ’ ll also need one additional method—a function that can be queried ( for a true or false answer ) as to whether the particle is alive or dead . this will come in handy when we are writing the particlesystem object , whose task will be to manage the list of particles themselves . writing this function is pretty easy ; we just need to check and see if the value of timetolive is less than 0 . if it is we return true , if not we return false . particle.prototype.isdead = function ( ) { if ( this.timetolive & lt ; 0 ) { return true ; } else { return false ; } } ; before we get to the next step of making many particles , it ’ s worth taking a moment to make sure our particle works correctly and create a sketch with one single particle object . here is the full code below , with two small additions . we add a convenience method called run ( ) that simply calls both update ( ) and display ( ) for us . in addition , we give the particle a random initial velocity as well as a downward acceleration ( to simulate gravity ) . now that we have an object to describe a single particle , we ’ re ready for the next big step . how do we keep track of many particles , when we can ’ t ensure exactly how many particles we might have at any given time ?
before we can create an entire particlesystem , we have to create an object that will describe a single particle . the good news : we 've done this already . our mover object from the forces section serves as the perfect template .
step 1 : is there a way to match the leaves ' positions to what the tree is already drawing ?
overview the pueblo people , native americans living in what is now new mexico , rose up against spanish conquistadores in the wake of religious persecution , violence , and drought . the uprising aimed to reclaim pueblo religious practices , culture , and land , which had been stripped away by spanish conquistadores . although the pueblo uprising ultimately failed to take back santa fe from spanish colonizers , the pueblo people made a lasting impact on the dominant culture of the southwest . pueblo uprising in santa fe having found wealth in mexico , the spanish looked north to expand their empire into the land of the pueblo people . the spanish expected present-day new mexico to yield gold and silver , but they were mistaken . instead , they established a political base in santa fe in 1610 , naming it the capital of the kingdom of new mexico . it became an outpost of the larger spanish viceroyalty of new spain , headquartered in mexico city . as they had in other spanish colonies , missionaries built churches and forced the pueblos to convert to catholicism , requiring native people to discard their own religious practices entirely . they focused their conversion projects on young pueblos , drawing them away from their parents and traditions . the spanish demanded corn and labor from the pueblos , but a long period of drought impeded production , escalating tension in santa fe . the pueblo also suffered increased attacks on their villages by rival native groups , which they attributed to the spanish presence . popé , a pueblo leader and medicine man led a response to the persecution and violence—a return to native customs . he popularized the idea that “ when jesus came , the corn mothers went away. ” this was a succinct way of describing the displacement of native traditions by the culture and religion of the spanish . in 1680 , the pueblo launched a coordinated attack on the spanish . pueblos , navajos , and apaches from the region congregated and planned to strike santa fe when the spaniards were low on supplies . they laid siege to the city for nine days and cut off the spanish water supply . the uprising , also known as popé ’ s rebellion , killed over 400 spaniards and drove the remaining 2,000 spanish settlers south toward mexico . participants in the rebellion also destroyed many mission churches in an effort to diminish catholic physical presence on pueblo land . pueblo historian joe s. sando calls the movement “ the first american revolution. ” the pueblo reestablished their religious institutions and a government of their own for the next 12 years of independence . however , as droughts and attacks by rival tribes continued , the spanish sensed an opportunity to regain their foothold . in 1692 , the spanish military returned and reasserted their control of the area . longterm effects of native american resistance although the spanish regained santa fe from the pueblos , their missionary vision was somewhat compromised by the sentiment stirred up during the uprising . many pueblo quietly resisted catholicism and folded their own cultural practices into norms instituted by the spanish . this produced religious syncretism—the amalgamation of the distinct religious cultures of the pueblos and the spanish . the spanish also slowly decreased their labor demands and the harsh practices of the encomienda system . over the course of the next few centuries , pueblo and spaniards intermarried . pueblo customs started to shape—and continue to heavily influence—new mexican culture . what do you think ? why did spanish missionaries persecute the pueblos and suppress their religious customs ? did the spanish succeed in suppressing pueblo culture ? why or why not ? how did the pueblo uprising contribute to the formation of a new ethnic identity in the southwest ?
in 1680 , the pueblo launched a coordinated attack on the spanish . pueblos , navajos , and apaches from the region congregated and planned to strike santa fe when the spaniards were low on supplies . they laid siege to the city for nine days and cut off the spanish water supply .
why were n't the navajos and apache groups as culturally influential to the spaniards ?
overview the pueblo people , native americans living in what is now new mexico , rose up against spanish conquistadores in the wake of religious persecution , violence , and drought . the uprising aimed to reclaim pueblo religious practices , culture , and land , which had been stripped away by spanish conquistadores . although the pueblo uprising ultimately failed to take back santa fe from spanish colonizers , the pueblo people made a lasting impact on the dominant culture of the southwest . pueblo uprising in santa fe having found wealth in mexico , the spanish looked north to expand their empire into the land of the pueblo people . the spanish expected present-day new mexico to yield gold and silver , but they were mistaken . instead , they established a political base in santa fe in 1610 , naming it the capital of the kingdom of new mexico . it became an outpost of the larger spanish viceroyalty of new spain , headquartered in mexico city . as they had in other spanish colonies , missionaries built churches and forced the pueblos to convert to catholicism , requiring native people to discard their own religious practices entirely . they focused their conversion projects on young pueblos , drawing them away from their parents and traditions . the spanish demanded corn and labor from the pueblos , but a long period of drought impeded production , escalating tension in santa fe . the pueblo also suffered increased attacks on their villages by rival native groups , which they attributed to the spanish presence . popé , a pueblo leader and medicine man led a response to the persecution and violence—a return to native customs . he popularized the idea that “ when jesus came , the corn mothers went away. ” this was a succinct way of describing the displacement of native traditions by the culture and religion of the spanish . in 1680 , the pueblo launched a coordinated attack on the spanish . pueblos , navajos , and apaches from the region congregated and planned to strike santa fe when the spaniards were low on supplies . they laid siege to the city for nine days and cut off the spanish water supply . the uprising , also known as popé ’ s rebellion , killed over 400 spaniards and drove the remaining 2,000 spanish settlers south toward mexico . participants in the rebellion also destroyed many mission churches in an effort to diminish catholic physical presence on pueblo land . pueblo historian joe s. sando calls the movement “ the first american revolution. ” the pueblo reestablished their religious institutions and a government of their own for the next 12 years of independence . however , as droughts and attacks by rival tribes continued , the spanish sensed an opportunity to regain their foothold . in 1692 , the spanish military returned and reasserted their control of the area . longterm effects of native american resistance although the spanish regained santa fe from the pueblos , their missionary vision was somewhat compromised by the sentiment stirred up during the uprising . many pueblo quietly resisted catholicism and folded their own cultural practices into norms instituted by the spanish . this produced religious syncretism—the amalgamation of the distinct religious cultures of the pueblos and the spanish . the spanish also slowly decreased their labor demands and the harsh practices of the encomienda system . over the course of the next few centuries , pueblo and spaniards intermarried . pueblo customs started to shape—and continue to heavily influence—new mexican culture . what do you think ? why did spanish missionaries persecute the pueblos and suppress their religious customs ? did the spanish succeed in suppressing pueblo culture ? why or why not ? how did the pueblo uprising contribute to the formation of a new ethnic identity in the southwest ?
overview the pueblo people , native americans living in what is now new mexico , rose up against spanish conquistadores in the wake of religious persecution , violence , and drought . the uprising aimed to reclaim pueblo religious practices , culture , and land , which had been stripped away by spanish conquistadores .
simply a difference in geographical locations ?
overview the pueblo people , native americans living in what is now new mexico , rose up against spanish conquistadores in the wake of religious persecution , violence , and drought . the uprising aimed to reclaim pueblo religious practices , culture , and land , which had been stripped away by spanish conquistadores . although the pueblo uprising ultimately failed to take back santa fe from spanish colonizers , the pueblo people made a lasting impact on the dominant culture of the southwest . pueblo uprising in santa fe having found wealth in mexico , the spanish looked north to expand their empire into the land of the pueblo people . the spanish expected present-day new mexico to yield gold and silver , but they were mistaken . instead , they established a political base in santa fe in 1610 , naming it the capital of the kingdom of new mexico . it became an outpost of the larger spanish viceroyalty of new spain , headquartered in mexico city . as they had in other spanish colonies , missionaries built churches and forced the pueblos to convert to catholicism , requiring native people to discard their own religious practices entirely . they focused their conversion projects on young pueblos , drawing them away from their parents and traditions . the spanish demanded corn and labor from the pueblos , but a long period of drought impeded production , escalating tension in santa fe . the pueblo also suffered increased attacks on their villages by rival native groups , which they attributed to the spanish presence . popé , a pueblo leader and medicine man led a response to the persecution and violence—a return to native customs . he popularized the idea that “ when jesus came , the corn mothers went away. ” this was a succinct way of describing the displacement of native traditions by the culture and religion of the spanish . in 1680 , the pueblo launched a coordinated attack on the spanish . pueblos , navajos , and apaches from the region congregated and planned to strike santa fe when the spaniards were low on supplies . they laid siege to the city for nine days and cut off the spanish water supply . the uprising , also known as popé ’ s rebellion , killed over 400 spaniards and drove the remaining 2,000 spanish settlers south toward mexico . participants in the rebellion also destroyed many mission churches in an effort to diminish catholic physical presence on pueblo land . pueblo historian joe s. sando calls the movement “ the first american revolution. ” the pueblo reestablished their religious institutions and a government of their own for the next 12 years of independence . however , as droughts and attacks by rival tribes continued , the spanish sensed an opportunity to regain their foothold . in 1692 , the spanish military returned and reasserted their control of the area . longterm effects of native american resistance although the spanish regained santa fe from the pueblos , their missionary vision was somewhat compromised by the sentiment stirred up during the uprising . many pueblo quietly resisted catholicism and folded their own cultural practices into norms instituted by the spanish . this produced religious syncretism—the amalgamation of the distinct religious cultures of the pueblos and the spanish . the spanish also slowly decreased their labor demands and the harsh practices of the encomienda system . over the course of the next few centuries , pueblo and spaniards intermarried . pueblo customs started to shape—and continue to heavily influence—new mexican culture . what do you think ? why did spanish missionaries persecute the pueblos and suppress their religious customs ? did the spanish succeed in suppressing pueblo culture ? why or why not ? how did the pueblo uprising contribute to the formation of a new ethnic identity in the southwest ?
although the pueblo uprising ultimately failed to take back santa fe from spanish colonizers , the pueblo people made a lasting impact on the dominant culture of the southwest . pueblo uprising in santa fe having found wealth in mexico , the spanish looked north to expand their empire into the land of the pueblo people . the spanish expected present-day new mexico to yield gold and silver , but they were mistaken . instead , they established a political base in santa fe in 1610 , naming it the capital of the kingdom of new mexico .
how long was mexico controlled by the spanish ?
biological oxidation of ethanol have you ever had a hangover ? that throbbing headache and feeling like a zombie is the punishment for drinking more than just a couple of alcoholic beverages . sounds familiar ? have you ever wondered what your body is doing and why your head hurts so much ? part of the problem is dehydration , but that isn ’ t the whole story . to get the full picture , we need to see how the body processes alcohol . this process is known as the ‘ biological oxidation of alcohols ’ . before looking at the way alcohol is processed in the body , let us start by figuring out what an alcohol molecule is . alcohols are organic compounds in which the hydroxyl functional group ( –oh ) is bound to a carbon atom . their general structure is alcohols are an important class of molecules with many scientific , medical , and industrial uses . an alcohol contains a hydrocarbon ( carbon/ hydrogen ) chain with an –oh functionality somewhere along the chain . it is this –oh group that identifies it as an alcohol . for example ethanol , the main alcohol found in beer , wine , and spirits has the chemical formula of ch $ { 3 } $ ch $ { 2 } $ oh . different alcohols will have different carbon/hydrogen chains . now that we know what a molecule of ethanol looks like , let us think about what happens when we drink a glass of beer . firstly , ethanol is completely soluble in water ( it mixes throughout the water in our body to form a uniform solution ) . for example , when you combine beer and lemonade together they completely mix . lemonade is basically flavored water . if beer wasn ’ t soluble in lemonade it wouldn ’ t mix together and you would see distinct layers between the two liquids . have you noticed what happens when you shake a bottle of salad dressing ( that constituents oil and vinegar ) , and then let it sit for a while ; the layers of oil and vinegar separate out . this illustrates oil is not soluble in water , but alcohol definitely is . our bodies are about 60 % water and when we drink a glass of beer , the ethanol molecules quickly absorb into our bloodstream through the stomach and the small intestines . once in the blood , the ethanol moves all around the body rapidly affecting the brain and we know “ what ” happens then ! the metabolism ( or breakdown ) of ethanol in the liver occurs in two steps , as illustrated below the first step of the alcohol metabolism process is the conversion of the alcohol to another class of organic molecules called an aldehyde . $ ch_3ch_2oh + nad^+ → ch_3cho + nadh + h^+ $ this aldehyde is called acetaldehyde or ethanal . ignore the nad $ ^\text { + } $ /nadh in this equation for now ; we will come back to that in a moment . the second step is the conversion of acetaldehyde into acetic acid . $ ch_3cho + nad^+ → ch_3cooh + nadh + h^+ $ acetic acid is an example of another class of organic molecules called a carboxylic acid . the overall reaction shows how an alcohol is oxidized in biochemistry . now there are various definitions for oxidation , but the one i want to use is “ oxidation is the gain of oxygen ” . actually , the very first scientists to discover oxidation and the opposite reaction , reduction , studied the addition and removal or oxygen . this definition works well here because you can see that the alcohol molecule has gained an oxygen atom . the overall change is from –oh to –ooh . this chemical conversion from ethanol to acetic acid can easily be carried out in any chemistry lab with the addition of an oxidizing agent like potassium dichromate ( k $ { 2 } $ cr $ { 2 } $ o $ { 7 } $ ) or sodium dichromate ( na $ { 2 } $ cr $ { 2 } $ o $ { 7 } $ ) in the presence of sulphuric acid . but this is not how this conversion takes place in our bodies ! this oxidation process is catalyzed by enzymes and coenzymes instead . let ’ s take a look at the role of the coenzymes in the oxidation process . the coenzymes are shown in the equations above as nad $ ^\text { + } $ /nadh . they differ only by one extra hydrogen atom . nad $ ^\text { + } $ ( nicotinamide adenine dinucleotide ) is the oxidized form and nadh is the reduced form . these coenzymes help the oxidation process by removing hydrogens and electrons . they are in fact the biological oxidizing agents ! the enzymes help by speeding up this process . first step of oxidation of ethanol is toxic to the human body ! now you may be wondering if the overall reaction is the main deal , why bother to even show the first step to acetaldehyde . great thought ! acetaldehyde is one of the chemicals responsible for the symptoms of a hangover . it isn ’ t the only chemical that does this , but it is considered a major contributor . acetaldehyde is toxic to our body and it is therefore important that it gets further oxidized to acetic acid as quickly as possible . acetaldehyde rapidly widens our blood vessels ( vasodilation ) to cause a flushing to the skin . at the same time , we start to experience headaches and other unpleasant effects of a hangover . how bad the hangover is largely depends on how quickly the body can get from the acetaldehyde to the harmless acetic acid ( the acid found in vinegar ) . drinking too many alcoholic drinks results in more acetaldehyde in our body than can be broken down . this buildup is caused because our enzymes can not process it through quickly enough . so let ’ s now turn our attention to these enzymes that are so critical to the oxidation of alcohols . enzymes are biological catalysts , meaning they speed up chemical reactions in biological systems . enzymes are required for both the steps of oxidation ( ethanol to acetaldehyde and acetaldehyde to acetic acid ) . there are two hepatic enzymes involved in the oxidation of ethanol in a human adult alcohol dehydrogenase ib ( class i ) - adh1b : oxidizes ethanol to acetaldehyde aldehyde dehydrogenase 2 - aldh2 : oxidizes acetaldehyde to acetic acid the latter ( aldh2 ) is critical to moving through the second , hangover inducing , step as quickly as possible . some people , particularly those from east-asia , carry a mutated version of the gene responsible for producing this enzyme . this mutated gene causes a significant build-up of acetaldehyde in the body . biological oxidation of methanol not all alcohols can be converted to something harmless ( like acetic acid ) . methanol is one such example . it chemically looks like ethanol , with the exception of the length of the carbon chain . methanol has the chemical formula of ch $ { 3 } $ oh compared to ch $ { 3 } $ ch $ _ { 2 } $ oh of ethanol . this subtle difference in structure makes a significant difference in its effect . methanol is exceptionally poisonous as it can cause blindness after consuming just less than 2 teaspoons , and a lethal dose is only about 2 tablespoons ! many people were blinded or died from drinking methanol during prohibition . the initial symptoms of methanol intoxication include depression , headache , dizziness , nausea , lack of coordination , and confusion . sufficiently large doses of methanol can cause unconsciousness and ultimately death . so why is methanol so toxic to the human body ? the answer lies in the products that are formed when it is oxidized within our body . methanol is metabolized in exactly the same way as ethanol . it is an oxidation reaction from an –oh to an –ooh . just like ethanol , the first step changes the alcohol to the aldehyde , and the second step changes the aldehyde to the carboxylic acid . from methanol though , formaldehyde and formic acid are produced instead of the harmless acetic acid ( as in the case of ethanol ) . both formaldehyde and formic acid ( methanoic acid ) are deadly , first attacking cells in the retina and then the cells of other vital organs . it is for this reason that methanol should never , ever be consumed . so next time you take a drink of beer or wine , just think about the chemical reactions taking place in your body !
just like ethanol , the first step changes the alcohol to the aldehyde , and the second step changes the aldehyde to the carboxylic acid . from methanol though , formaldehyde and formic acid are produced instead of the harmless acetic acid ( as in the case of ethanol ) . both formaldehyde and formic acid ( methanoic acid ) are deadly , first attacking cells in the retina and then the cells of other vital organs .
how long does it take for ethanol to oxidize to ethanoic acid in wine ?
biological oxidation of ethanol have you ever had a hangover ? that throbbing headache and feeling like a zombie is the punishment for drinking more than just a couple of alcoholic beverages . sounds familiar ? have you ever wondered what your body is doing and why your head hurts so much ? part of the problem is dehydration , but that isn ’ t the whole story . to get the full picture , we need to see how the body processes alcohol . this process is known as the ‘ biological oxidation of alcohols ’ . before looking at the way alcohol is processed in the body , let us start by figuring out what an alcohol molecule is . alcohols are organic compounds in which the hydroxyl functional group ( –oh ) is bound to a carbon atom . their general structure is alcohols are an important class of molecules with many scientific , medical , and industrial uses . an alcohol contains a hydrocarbon ( carbon/ hydrogen ) chain with an –oh functionality somewhere along the chain . it is this –oh group that identifies it as an alcohol . for example ethanol , the main alcohol found in beer , wine , and spirits has the chemical formula of ch $ { 3 } $ ch $ { 2 } $ oh . different alcohols will have different carbon/hydrogen chains . now that we know what a molecule of ethanol looks like , let us think about what happens when we drink a glass of beer . firstly , ethanol is completely soluble in water ( it mixes throughout the water in our body to form a uniform solution ) . for example , when you combine beer and lemonade together they completely mix . lemonade is basically flavored water . if beer wasn ’ t soluble in lemonade it wouldn ’ t mix together and you would see distinct layers between the two liquids . have you noticed what happens when you shake a bottle of salad dressing ( that constituents oil and vinegar ) , and then let it sit for a while ; the layers of oil and vinegar separate out . this illustrates oil is not soluble in water , but alcohol definitely is . our bodies are about 60 % water and when we drink a glass of beer , the ethanol molecules quickly absorb into our bloodstream through the stomach and the small intestines . once in the blood , the ethanol moves all around the body rapidly affecting the brain and we know “ what ” happens then ! the metabolism ( or breakdown ) of ethanol in the liver occurs in two steps , as illustrated below the first step of the alcohol metabolism process is the conversion of the alcohol to another class of organic molecules called an aldehyde . $ ch_3ch_2oh + nad^+ → ch_3cho + nadh + h^+ $ this aldehyde is called acetaldehyde or ethanal . ignore the nad $ ^\text { + } $ /nadh in this equation for now ; we will come back to that in a moment . the second step is the conversion of acetaldehyde into acetic acid . $ ch_3cho + nad^+ → ch_3cooh + nadh + h^+ $ acetic acid is an example of another class of organic molecules called a carboxylic acid . the overall reaction shows how an alcohol is oxidized in biochemistry . now there are various definitions for oxidation , but the one i want to use is “ oxidation is the gain of oxygen ” . actually , the very first scientists to discover oxidation and the opposite reaction , reduction , studied the addition and removal or oxygen . this definition works well here because you can see that the alcohol molecule has gained an oxygen atom . the overall change is from –oh to –ooh . this chemical conversion from ethanol to acetic acid can easily be carried out in any chemistry lab with the addition of an oxidizing agent like potassium dichromate ( k $ { 2 } $ cr $ { 2 } $ o $ { 7 } $ ) or sodium dichromate ( na $ { 2 } $ cr $ { 2 } $ o $ { 7 } $ ) in the presence of sulphuric acid . but this is not how this conversion takes place in our bodies ! this oxidation process is catalyzed by enzymes and coenzymes instead . let ’ s take a look at the role of the coenzymes in the oxidation process . the coenzymes are shown in the equations above as nad $ ^\text { + } $ /nadh . they differ only by one extra hydrogen atom . nad $ ^\text { + } $ ( nicotinamide adenine dinucleotide ) is the oxidized form and nadh is the reduced form . these coenzymes help the oxidation process by removing hydrogens and electrons . they are in fact the biological oxidizing agents ! the enzymes help by speeding up this process . first step of oxidation of ethanol is toxic to the human body ! now you may be wondering if the overall reaction is the main deal , why bother to even show the first step to acetaldehyde . great thought ! acetaldehyde is one of the chemicals responsible for the symptoms of a hangover . it isn ’ t the only chemical that does this , but it is considered a major contributor . acetaldehyde is toxic to our body and it is therefore important that it gets further oxidized to acetic acid as quickly as possible . acetaldehyde rapidly widens our blood vessels ( vasodilation ) to cause a flushing to the skin . at the same time , we start to experience headaches and other unpleasant effects of a hangover . how bad the hangover is largely depends on how quickly the body can get from the acetaldehyde to the harmless acetic acid ( the acid found in vinegar ) . drinking too many alcoholic drinks results in more acetaldehyde in our body than can be broken down . this buildup is caused because our enzymes can not process it through quickly enough . so let ’ s now turn our attention to these enzymes that are so critical to the oxidation of alcohols . enzymes are biological catalysts , meaning they speed up chemical reactions in biological systems . enzymes are required for both the steps of oxidation ( ethanol to acetaldehyde and acetaldehyde to acetic acid ) . there are two hepatic enzymes involved in the oxidation of ethanol in a human adult alcohol dehydrogenase ib ( class i ) - adh1b : oxidizes ethanol to acetaldehyde aldehyde dehydrogenase 2 - aldh2 : oxidizes acetaldehyde to acetic acid the latter ( aldh2 ) is critical to moving through the second , hangover inducing , step as quickly as possible . some people , particularly those from east-asia , carry a mutated version of the gene responsible for producing this enzyme . this mutated gene causes a significant build-up of acetaldehyde in the body . biological oxidation of methanol not all alcohols can be converted to something harmless ( like acetic acid ) . methanol is one such example . it chemically looks like ethanol , with the exception of the length of the carbon chain . methanol has the chemical formula of ch $ { 3 } $ oh compared to ch $ { 3 } $ ch $ _ { 2 } $ oh of ethanol . this subtle difference in structure makes a significant difference in its effect . methanol is exceptionally poisonous as it can cause blindness after consuming just less than 2 teaspoons , and a lethal dose is only about 2 tablespoons ! many people were blinded or died from drinking methanol during prohibition . the initial symptoms of methanol intoxication include depression , headache , dizziness , nausea , lack of coordination , and confusion . sufficiently large doses of methanol can cause unconsciousness and ultimately death . so why is methanol so toxic to the human body ? the answer lies in the products that are formed when it is oxidized within our body . methanol is metabolized in exactly the same way as ethanol . it is an oxidation reaction from an –oh to an –ooh . just like ethanol , the first step changes the alcohol to the aldehyde , and the second step changes the aldehyde to the carboxylic acid . from methanol though , formaldehyde and formic acid are produced instead of the harmless acetic acid ( as in the case of ethanol ) . both formaldehyde and formic acid ( methanoic acid ) are deadly , first attacking cells in the retina and then the cells of other vital organs . it is for this reason that methanol should never , ever be consumed . so next time you take a drink of beer or wine , just think about the chemical reactions taking place in your body !
the overall reaction shows how an alcohol is oxidized in biochemistry . now there are various definitions for oxidation , but the one i want to use is “ oxidation is the gain of oxygen ” . actually , the very first scientists to discover oxidation and the opposite reaction , reduction , studied the addition and removal or oxygen .
can we use ad for phenols ?
introduction we 've done a few examples of direct application of ohm 's law when we derived equations for series and parallel resistors , a voltage divider , and simplifying a resistor network . now we do an example that puts kirchhoff 's laws to work for us , too . we call this the application of the fundamental laws . task : find the unknown currents and voltages in this circuit . the steps to a solution involve creating and solving a system of independent equations , label the voltages and currents using the sign convention for passive components . select the independent variable , either $ i $ or $ v $ to produce the simplest equations . write equations using kcl , kvl , or both . make sure every element is represented in at least one equation . solve the system of equations . solve for any remaining unknown voltages and currents you want to know . step 1 : label the schematic to start , it helps to give names to voltages , currents , and nodes , and make a list of what we do and do not know . circuit features and unknowns : $ 5 $ elements $ 3 $ nodes , labeled $ \green a $ , $ \green b $ , and $ \green c $ . $ 3 $ meshes ( inner loops ) . $ 1 $ source voltage , $ v_ { \text s } $ , and $ 2 $ element voltages , $ v_1 $ and $ v_2 $ . $ 1 $ source current , $ i_ { \text s } $ , and $ 3 $ element currents , $ i_1 $ , $ i_2 $ and $ i_3 $ . when assigning polarity to the voltage and current of each element , we use the sign convention for passive components : the current arrow points into the positive voltage end of each resistor . to emphasize there are only three nodes in this circuit , it is redrawn here to highlight the junctions at nodes $ b $ and $ c $ . ( there is an obvious opportunity here to simplify the two parallel resistors , $ 6\ , \omega $ with $ 5\ , \omega $ . we will not do that , because we want to study the general analysis procedure . ) step 2 . select the independent variable at this point we have a choice to make . should the independent variable be voltage $ v $ or current $ i $ ? one good way to make this choice is to compare the number of unknown voltages to unknown currents . there are $ 2 $ unknown voltages , and $ 3 $ unknown currents . if we select voltage as the independent variable , we will have equations with $ 2 $ voltage terms as opposed to $ 3 $ current terms . $ 2 $ is simpler , so voltage will be the independent variable for this problem . step 3 . write independent equations since we have two unknown voltages , we need two independent equations to solve for them . our choice will be a kvl equation around the left-most mesh and a kcl equation at node $ \green b $ . why did i make these particular choices ? i picked the two most interesting features of the circuit . node $ \green b $ has several connections , making it an interesting focal point for the circuit , and the left-most mesh nicely includes the all the remaining circuit elements not fully controlled by node $ \green b $ . admittedly , i used some of my own experience in electronics to anticipate the direction the analysis will take . as you do more problems of this sort , you will build your intuition , too . kvl around the left-most mesh the left-most mesh is the one with the orange circle . we start at the lower left corner of the circuit , where you see the ground symbol , and go clockwise around the mesh adding up voltages . kirchhoff 's voltage law says the sum of element voltages around a loop must add up to zero . $ +v_ { \text { s } } - v_1 - v_2 = 0 $ $ +140 - v_1 - v_2 = 0 $ the $ - $ signs for $ v_1 $ and $ v_2 $ are because we encounter their $ + $ sign first during the clockwise tour around the loop , indicating we will see a voltage drop as we go through the component . kcl at node $ \green b $ we will get our second equation by writing kirchhoff 's current law at node $ \green b $ . one form of kirchhoff 's current law says the currents flowing into a node must equal the currents flowing out of the node . add up the currents flowing into node $ \green b $ , set them equal to the sum of currents flowing out . $ i_1 + i_ { \text s } = i_2 + i_3 $ earlier in step 2. we decided to use $ v_1 $ and $ v_2 $ as the independent variables , so we use ohm 's law to express the unknown currents in terms of voltage and resistance . $ \dfrac { v_1 } { 20\ , \omega } + 18 = \dfrac { v_2 } { 6\ , \omega } + \dfrac { v_2 } { 5\ , \omega } $ after a little rearrangement , we have our system of two equations in two unknowns , $ v_1 + v_2 = 140 $ $ \dfrac { 1 } { 20 } v_1 - \left ( \dfrac { 1 } { 6 } + \dfrac { 1 } { 5 } \right ) v_2 = -18 $ these two equations capture everything going on in our circuit . this is a good time to do a quick check . did every circuit element get a chance to participate in at least one equation ? are any left out ? account for all $ 5 $ elements . steps 4 and 5 - solve have a go at solving this system of equations yourself before looking at the full answer below . find unknown voltages $ v_1 $ and $ v_2 $ , and unknown currents $ i_1 $ , $ i_2 $ , and $ i_3 $ . summary we solved a circuit by direct application of the fundamental laws . our tools were ohm 's law and kirchhoff 's laws . the steps to a solution : label voltages and currents using the sign convention for passive components . select the independent variable , either $ i $ or $ v $ to produce the simplest equations . choose the variable with the fewest unknowns . write equations using kcl , kvl , or both . make sure every element is represented in at least one equation . solve the system of equations for the independent variables ( in this case , $ v_1 $ and $ v_2 $ ) . solve for the other unknowns . $ $ our approach to solving this circuit was solidly based on the fundamental laws , and we got the right answer . but our choice of equations felt somewhat arbitrary . coming up next , we will talk about two efficient and well-organized methods for solving any circuit , the node voltage method , and the mesh current method .
$ +v_ { \text { s } } - v_1 - v_2 = 0 $ $ +140 - v_1 - v_2 = 0 $ the $ - $ signs for $ v_1 $ and $ v_2 $ are because we encounter their $ + $ sign first during the clockwise tour around the loop , indicating we will see a voltage drop as we go through the component . kcl at node $ \green b $ we will get our second equation by writing kirchhoff 's current law at node $ \green b $ . one form of kirchhoff 's current law says the currents flowing into a node must equal the currents flowing out of the node .
at the point where kcl is calculated at node b , why is the voltage same for currents i2 and i3 ?
introduction we 've done a few examples of direct application of ohm 's law when we derived equations for series and parallel resistors , a voltage divider , and simplifying a resistor network . now we do an example that puts kirchhoff 's laws to work for us , too . we call this the application of the fundamental laws . task : find the unknown currents and voltages in this circuit . the steps to a solution involve creating and solving a system of independent equations , label the voltages and currents using the sign convention for passive components . select the independent variable , either $ i $ or $ v $ to produce the simplest equations . write equations using kcl , kvl , or both . make sure every element is represented in at least one equation . solve the system of equations . solve for any remaining unknown voltages and currents you want to know . step 1 : label the schematic to start , it helps to give names to voltages , currents , and nodes , and make a list of what we do and do not know . circuit features and unknowns : $ 5 $ elements $ 3 $ nodes , labeled $ \green a $ , $ \green b $ , and $ \green c $ . $ 3 $ meshes ( inner loops ) . $ 1 $ source voltage , $ v_ { \text s } $ , and $ 2 $ element voltages , $ v_1 $ and $ v_2 $ . $ 1 $ source current , $ i_ { \text s } $ , and $ 3 $ element currents , $ i_1 $ , $ i_2 $ and $ i_3 $ . when assigning polarity to the voltage and current of each element , we use the sign convention for passive components : the current arrow points into the positive voltage end of each resistor . to emphasize there are only three nodes in this circuit , it is redrawn here to highlight the junctions at nodes $ b $ and $ c $ . ( there is an obvious opportunity here to simplify the two parallel resistors , $ 6\ , \omega $ with $ 5\ , \omega $ . we will not do that , because we want to study the general analysis procedure . ) step 2 . select the independent variable at this point we have a choice to make . should the independent variable be voltage $ v $ or current $ i $ ? one good way to make this choice is to compare the number of unknown voltages to unknown currents . there are $ 2 $ unknown voltages , and $ 3 $ unknown currents . if we select voltage as the independent variable , we will have equations with $ 2 $ voltage terms as opposed to $ 3 $ current terms . $ 2 $ is simpler , so voltage will be the independent variable for this problem . step 3 . write independent equations since we have two unknown voltages , we need two independent equations to solve for them . our choice will be a kvl equation around the left-most mesh and a kcl equation at node $ \green b $ . why did i make these particular choices ? i picked the two most interesting features of the circuit . node $ \green b $ has several connections , making it an interesting focal point for the circuit , and the left-most mesh nicely includes the all the remaining circuit elements not fully controlled by node $ \green b $ . admittedly , i used some of my own experience in electronics to anticipate the direction the analysis will take . as you do more problems of this sort , you will build your intuition , too . kvl around the left-most mesh the left-most mesh is the one with the orange circle . we start at the lower left corner of the circuit , where you see the ground symbol , and go clockwise around the mesh adding up voltages . kirchhoff 's voltage law says the sum of element voltages around a loop must add up to zero . $ +v_ { \text { s } } - v_1 - v_2 = 0 $ $ +140 - v_1 - v_2 = 0 $ the $ - $ signs for $ v_1 $ and $ v_2 $ are because we encounter their $ + $ sign first during the clockwise tour around the loop , indicating we will see a voltage drop as we go through the component . kcl at node $ \green b $ we will get our second equation by writing kirchhoff 's current law at node $ \green b $ . one form of kirchhoff 's current law says the currents flowing into a node must equal the currents flowing out of the node . add up the currents flowing into node $ \green b $ , set them equal to the sum of currents flowing out . $ i_1 + i_ { \text s } = i_2 + i_3 $ earlier in step 2. we decided to use $ v_1 $ and $ v_2 $ as the independent variables , so we use ohm 's law to express the unknown currents in terms of voltage and resistance . $ \dfrac { v_1 } { 20\ , \omega } + 18 = \dfrac { v_2 } { 6\ , \omega } + \dfrac { v_2 } { 5\ , \omega } $ after a little rearrangement , we have our system of two equations in two unknowns , $ v_1 + v_2 = 140 $ $ \dfrac { 1 } { 20 } v_1 - \left ( \dfrac { 1 } { 6 } + \dfrac { 1 } { 5 } \right ) v_2 = -18 $ these two equations capture everything going on in our circuit . this is a good time to do a quick check . did every circuit element get a chance to participate in at least one equation ? are any left out ? account for all $ 5 $ elements . steps 4 and 5 - solve have a go at solving this system of equations yourself before looking at the full answer below . find unknown voltages $ v_1 $ and $ v_2 $ , and unknown currents $ i_1 $ , $ i_2 $ , and $ i_3 $ . summary we solved a circuit by direct application of the fundamental laws . our tools were ohm 's law and kirchhoff 's laws . the steps to a solution : label voltages and currents using the sign convention for passive components . select the independent variable , either $ i $ or $ v $ to produce the simplest equations . choose the variable with the fewest unknowns . write equations using kcl , kvl , or both . make sure every element is represented in at least one equation . solve the system of equations for the independent variables ( in this case , $ v_1 $ and $ v_2 $ ) . solve for the other unknowns . $ $ our approach to solving this circuit was solidly based on the fundamental laws , and we got the right answer . but our choice of equations felt somewhat arbitrary . coming up next , we will talk about two efficient and well-organized methods for solving any circuit , the node voltage method , and the mesh current method .
select the independent variable at this point we have a choice to make . should the independent variable be voltage $ v $ or current $ i $ ? one good way to make this choice is to compare the number of unknown voltages to unknown currents .
how is it that current flows `` up '' through the current source in this example , from lower voltage to higher voltage ?
introduction we 've done a few examples of direct application of ohm 's law when we derived equations for series and parallel resistors , a voltage divider , and simplifying a resistor network . now we do an example that puts kirchhoff 's laws to work for us , too . we call this the application of the fundamental laws . task : find the unknown currents and voltages in this circuit . the steps to a solution involve creating and solving a system of independent equations , label the voltages and currents using the sign convention for passive components . select the independent variable , either $ i $ or $ v $ to produce the simplest equations . write equations using kcl , kvl , or both . make sure every element is represented in at least one equation . solve the system of equations . solve for any remaining unknown voltages and currents you want to know . step 1 : label the schematic to start , it helps to give names to voltages , currents , and nodes , and make a list of what we do and do not know . circuit features and unknowns : $ 5 $ elements $ 3 $ nodes , labeled $ \green a $ , $ \green b $ , and $ \green c $ . $ 3 $ meshes ( inner loops ) . $ 1 $ source voltage , $ v_ { \text s } $ , and $ 2 $ element voltages , $ v_1 $ and $ v_2 $ . $ 1 $ source current , $ i_ { \text s } $ , and $ 3 $ element currents , $ i_1 $ , $ i_2 $ and $ i_3 $ . when assigning polarity to the voltage and current of each element , we use the sign convention for passive components : the current arrow points into the positive voltage end of each resistor . to emphasize there are only three nodes in this circuit , it is redrawn here to highlight the junctions at nodes $ b $ and $ c $ . ( there is an obvious opportunity here to simplify the two parallel resistors , $ 6\ , \omega $ with $ 5\ , \omega $ . we will not do that , because we want to study the general analysis procedure . ) step 2 . select the independent variable at this point we have a choice to make . should the independent variable be voltage $ v $ or current $ i $ ? one good way to make this choice is to compare the number of unknown voltages to unknown currents . there are $ 2 $ unknown voltages , and $ 3 $ unknown currents . if we select voltage as the independent variable , we will have equations with $ 2 $ voltage terms as opposed to $ 3 $ current terms . $ 2 $ is simpler , so voltage will be the independent variable for this problem . step 3 . write independent equations since we have two unknown voltages , we need two independent equations to solve for them . our choice will be a kvl equation around the left-most mesh and a kcl equation at node $ \green b $ . why did i make these particular choices ? i picked the two most interesting features of the circuit . node $ \green b $ has several connections , making it an interesting focal point for the circuit , and the left-most mesh nicely includes the all the remaining circuit elements not fully controlled by node $ \green b $ . admittedly , i used some of my own experience in electronics to anticipate the direction the analysis will take . as you do more problems of this sort , you will build your intuition , too . kvl around the left-most mesh the left-most mesh is the one with the orange circle . we start at the lower left corner of the circuit , where you see the ground symbol , and go clockwise around the mesh adding up voltages . kirchhoff 's voltage law says the sum of element voltages around a loop must add up to zero . $ +v_ { \text { s } } - v_1 - v_2 = 0 $ $ +140 - v_1 - v_2 = 0 $ the $ - $ signs for $ v_1 $ and $ v_2 $ are because we encounter their $ + $ sign first during the clockwise tour around the loop , indicating we will see a voltage drop as we go through the component . kcl at node $ \green b $ we will get our second equation by writing kirchhoff 's current law at node $ \green b $ . one form of kirchhoff 's current law says the currents flowing into a node must equal the currents flowing out of the node . add up the currents flowing into node $ \green b $ , set them equal to the sum of currents flowing out . $ i_1 + i_ { \text s } = i_2 + i_3 $ earlier in step 2. we decided to use $ v_1 $ and $ v_2 $ as the independent variables , so we use ohm 's law to express the unknown currents in terms of voltage and resistance . $ \dfrac { v_1 } { 20\ , \omega } + 18 = \dfrac { v_2 } { 6\ , \omega } + \dfrac { v_2 } { 5\ , \omega } $ after a little rearrangement , we have our system of two equations in two unknowns , $ v_1 + v_2 = 140 $ $ \dfrac { 1 } { 20 } v_1 - \left ( \dfrac { 1 } { 6 } + \dfrac { 1 } { 5 } \right ) v_2 = -18 $ these two equations capture everything going on in our circuit . this is a good time to do a quick check . did every circuit element get a chance to participate in at least one equation ? are any left out ? account for all $ 5 $ elements . steps 4 and 5 - solve have a go at solving this system of equations yourself before looking at the full answer below . find unknown voltages $ v_1 $ and $ v_2 $ , and unknown currents $ i_1 $ , $ i_2 $ , and $ i_3 $ . summary we solved a circuit by direct application of the fundamental laws . our tools were ohm 's law and kirchhoff 's laws . the steps to a solution : label voltages and currents using the sign convention for passive components . select the independent variable , either $ i $ or $ v $ to produce the simplest equations . choose the variable with the fewest unknowns . write equations using kcl , kvl , or both . make sure every element is represented in at least one equation . solve the system of equations for the independent variables ( in this case , $ v_1 $ and $ v_2 $ ) . solve for the other unknowns . $ $ our approach to solving this circuit was solidly based on the fundamental laws , and we got the right answer . but our choice of equations felt somewhat arbitrary . coming up next , we will talk about two efficient and well-organized methods for solving any circuit , the node voltage method , and the mesh current method .
introduction we 've done a few examples of direct application of ohm 's law when we derived equations for series and parallel resistors , a voltage divider , and simplifying a resistor network . now we do an example that puts kirchhoff 's laws to work for us , too .
why is n't there a voltage over the 5 ohm resistor ?
introduction we 've done a few examples of direct application of ohm 's law when we derived equations for series and parallel resistors , a voltage divider , and simplifying a resistor network . now we do an example that puts kirchhoff 's laws to work for us , too . we call this the application of the fundamental laws . task : find the unknown currents and voltages in this circuit . the steps to a solution involve creating and solving a system of independent equations , label the voltages and currents using the sign convention for passive components . select the independent variable , either $ i $ or $ v $ to produce the simplest equations . write equations using kcl , kvl , or both . make sure every element is represented in at least one equation . solve the system of equations . solve for any remaining unknown voltages and currents you want to know . step 1 : label the schematic to start , it helps to give names to voltages , currents , and nodes , and make a list of what we do and do not know . circuit features and unknowns : $ 5 $ elements $ 3 $ nodes , labeled $ \green a $ , $ \green b $ , and $ \green c $ . $ 3 $ meshes ( inner loops ) . $ 1 $ source voltage , $ v_ { \text s } $ , and $ 2 $ element voltages , $ v_1 $ and $ v_2 $ . $ 1 $ source current , $ i_ { \text s } $ , and $ 3 $ element currents , $ i_1 $ , $ i_2 $ and $ i_3 $ . when assigning polarity to the voltage and current of each element , we use the sign convention for passive components : the current arrow points into the positive voltage end of each resistor . to emphasize there are only three nodes in this circuit , it is redrawn here to highlight the junctions at nodes $ b $ and $ c $ . ( there is an obvious opportunity here to simplify the two parallel resistors , $ 6\ , \omega $ with $ 5\ , \omega $ . we will not do that , because we want to study the general analysis procedure . ) step 2 . select the independent variable at this point we have a choice to make . should the independent variable be voltage $ v $ or current $ i $ ? one good way to make this choice is to compare the number of unknown voltages to unknown currents . there are $ 2 $ unknown voltages , and $ 3 $ unknown currents . if we select voltage as the independent variable , we will have equations with $ 2 $ voltage terms as opposed to $ 3 $ current terms . $ 2 $ is simpler , so voltage will be the independent variable for this problem . step 3 . write independent equations since we have two unknown voltages , we need two independent equations to solve for them . our choice will be a kvl equation around the left-most mesh and a kcl equation at node $ \green b $ . why did i make these particular choices ? i picked the two most interesting features of the circuit . node $ \green b $ has several connections , making it an interesting focal point for the circuit , and the left-most mesh nicely includes the all the remaining circuit elements not fully controlled by node $ \green b $ . admittedly , i used some of my own experience in electronics to anticipate the direction the analysis will take . as you do more problems of this sort , you will build your intuition , too . kvl around the left-most mesh the left-most mesh is the one with the orange circle . we start at the lower left corner of the circuit , where you see the ground symbol , and go clockwise around the mesh adding up voltages . kirchhoff 's voltage law says the sum of element voltages around a loop must add up to zero . $ +v_ { \text { s } } - v_1 - v_2 = 0 $ $ +140 - v_1 - v_2 = 0 $ the $ - $ signs for $ v_1 $ and $ v_2 $ are because we encounter their $ + $ sign first during the clockwise tour around the loop , indicating we will see a voltage drop as we go through the component . kcl at node $ \green b $ we will get our second equation by writing kirchhoff 's current law at node $ \green b $ . one form of kirchhoff 's current law says the currents flowing into a node must equal the currents flowing out of the node . add up the currents flowing into node $ \green b $ , set them equal to the sum of currents flowing out . $ i_1 + i_ { \text s } = i_2 + i_3 $ earlier in step 2. we decided to use $ v_1 $ and $ v_2 $ as the independent variables , so we use ohm 's law to express the unknown currents in terms of voltage and resistance . $ \dfrac { v_1 } { 20\ , \omega } + 18 = \dfrac { v_2 } { 6\ , \omega } + \dfrac { v_2 } { 5\ , \omega } $ after a little rearrangement , we have our system of two equations in two unknowns , $ v_1 + v_2 = 140 $ $ \dfrac { 1 } { 20 } v_1 - \left ( \dfrac { 1 } { 6 } + \dfrac { 1 } { 5 } \right ) v_2 = -18 $ these two equations capture everything going on in our circuit . this is a good time to do a quick check . did every circuit element get a chance to participate in at least one equation ? are any left out ? account for all $ 5 $ elements . steps 4 and 5 - solve have a go at solving this system of equations yourself before looking at the full answer below . find unknown voltages $ v_1 $ and $ v_2 $ , and unknown currents $ i_1 $ , $ i_2 $ , and $ i_3 $ . summary we solved a circuit by direct application of the fundamental laws . our tools were ohm 's law and kirchhoff 's laws . the steps to a solution : label voltages and currents using the sign convention for passive components . select the independent variable , either $ i $ or $ v $ to produce the simplest equations . choose the variable with the fewest unknowns . write equations using kcl , kvl , or both . make sure every element is represented in at least one equation . solve the system of equations for the independent variables ( in this case , $ v_1 $ and $ v_2 $ ) . solve for the other unknowns . $ $ our approach to solving this circuit was solidly based on the fundamental laws , and we got the right answer . but our choice of equations felt somewhat arbitrary . coming up next , we will talk about two efficient and well-organized methods for solving any circuit , the node voltage method , and the mesh current method .
we call this the application of the fundamental laws . task : find the unknown currents and voltages in this circuit . the steps to a solution involve creating and solving a system of independent equations , label the voltages and currents using the sign convention for passive components .
is the reason for this because , in a round about way , we have already resolved the currents ( or voltages ) accordingly so that ohm 's law , as it pertains specifically to parallel and series circuits , does n't apply anymore ?
introduction we 've done a few examples of direct application of ohm 's law when we derived equations for series and parallel resistors , a voltage divider , and simplifying a resistor network . now we do an example that puts kirchhoff 's laws to work for us , too . we call this the application of the fundamental laws . task : find the unknown currents and voltages in this circuit . the steps to a solution involve creating and solving a system of independent equations , label the voltages and currents using the sign convention for passive components . select the independent variable , either $ i $ or $ v $ to produce the simplest equations . write equations using kcl , kvl , or both . make sure every element is represented in at least one equation . solve the system of equations . solve for any remaining unknown voltages and currents you want to know . step 1 : label the schematic to start , it helps to give names to voltages , currents , and nodes , and make a list of what we do and do not know . circuit features and unknowns : $ 5 $ elements $ 3 $ nodes , labeled $ \green a $ , $ \green b $ , and $ \green c $ . $ 3 $ meshes ( inner loops ) . $ 1 $ source voltage , $ v_ { \text s } $ , and $ 2 $ element voltages , $ v_1 $ and $ v_2 $ . $ 1 $ source current , $ i_ { \text s } $ , and $ 3 $ element currents , $ i_1 $ , $ i_2 $ and $ i_3 $ . when assigning polarity to the voltage and current of each element , we use the sign convention for passive components : the current arrow points into the positive voltage end of each resistor . to emphasize there are only three nodes in this circuit , it is redrawn here to highlight the junctions at nodes $ b $ and $ c $ . ( there is an obvious opportunity here to simplify the two parallel resistors , $ 6\ , \omega $ with $ 5\ , \omega $ . we will not do that , because we want to study the general analysis procedure . ) step 2 . select the independent variable at this point we have a choice to make . should the independent variable be voltage $ v $ or current $ i $ ? one good way to make this choice is to compare the number of unknown voltages to unknown currents . there are $ 2 $ unknown voltages , and $ 3 $ unknown currents . if we select voltage as the independent variable , we will have equations with $ 2 $ voltage terms as opposed to $ 3 $ current terms . $ 2 $ is simpler , so voltage will be the independent variable for this problem . step 3 . write independent equations since we have two unknown voltages , we need two independent equations to solve for them . our choice will be a kvl equation around the left-most mesh and a kcl equation at node $ \green b $ . why did i make these particular choices ? i picked the two most interesting features of the circuit . node $ \green b $ has several connections , making it an interesting focal point for the circuit , and the left-most mesh nicely includes the all the remaining circuit elements not fully controlled by node $ \green b $ . admittedly , i used some of my own experience in electronics to anticipate the direction the analysis will take . as you do more problems of this sort , you will build your intuition , too . kvl around the left-most mesh the left-most mesh is the one with the orange circle . we start at the lower left corner of the circuit , where you see the ground symbol , and go clockwise around the mesh adding up voltages . kirchhoff 's voltage law says the sum of element voltages around a loop must add up to zero . $ +v_ { \text { s } } - v_1 - v_2 = 0 $ $ +140 - v_1 - v_2 = 0 $ the $ - $ signs for $ v_1 $ and $ v_2 $ are because we encounter their $ + $ sign first during the clockwise tour around the loop , indicating we will see a voltage drop as we go through the component . kcl at node $ \green b $ we will get our second equation by writing kirchhoff 's current law at node $ \green b $ . one form of kirchhoff 's current law says the currents flowing into a node must equal the currents flowing out of the node . add up the currents flowing into node $ \green b $ , set them equal to the sum of currents flowing out . $ i_1 + i_ { \text s } = i_2 + i_3 $ earlier in step 2. we decided to use $ v_1 $ and $ v_2 $ as the independent variables , so we use ohm 's law to express the unknown currents in terms of voltage and resistance . $ \dfrac { v_1 } { 20\ , \omega } + 18 = \dfrac { v_2 } { 6\ , \omega } + \dfrac { v_2 } { 5\ , \omega } $ after a little rearrangement , we have our system of two equations in two unknowns , $ v_1 + v_2 = 140 $ $ \dfrac { 1 } { 20 } v_1 - \left ( \dfrac { 1 } { 6 } + \dfrac { 1 } { 5 } \right ) v_2 = -18 $ these two equations capture everything going on in our circuit . this is a good time to do a quick check . did every circuit element get a chance to participate in at least one equation ? are any left out ? account for all $ 5 $ elements . steps 4 and 5 - solve have a go at solving this system of equations yourself before looking at the full answer below . find unknown voltages $ v_1 $ and $ v_2 $ , and unknown currents $ i_1 $ , $ i_2 $ , and $ i_3 $ . summary we solved a circuit by direct application of the fundamental laws . our tools were ohm 's law and kirchhoff 's laws . the steps to a solution : label voltages and currents using the sign convention for passive components . select the independent variable , either $ i $ or $ v $ to produce the simplest equations . choose the variable with the fewest unknowns . write equations using kcl , kvl , or both . make sure every element is represented in at least one equation . solve the system of equations for the independent variables ( in this case , $ v_1 $ and $ v_2 $ ) . solve for the other unknowns . $ $ our approach to solving this circuit was solidly based on the fundamental laws , and we got the right answer . but our choice of equations felt somewhat arbitrary . coming up next , we will talk about two efficient and well-organized methods for solving any circuit , the node voltage method , and the mesh current method .
$ +v_ { \text { s } } - v_1 - v_2 = 0 $ $ +140 - v_1 - v_2 = 0 $ the $ - $ signs for $ v_1 $ and $ v_2 $ are because we encounter their $ + $ sign first during the clockwise tour around the loop , indicating we will see a voltage drop as we go through the component . kcl at node $ \green b $ we will get our second equation by writing kirchhoff 's current law at node $ \green b $ . one form of kirchhoff 's current law says the currents flowing into a node must equal the currents flowing out of the node . add up the currents flowing into node $ \green b $ , set them equal to the sum of currents flowing out .
how would one label the current flow in node c ?
introduction we 've done a few examples of direct application of ohm 's law when we derived equations for series and parallel resistors , a voltage divider , and simplifying a resistor network . now we do an example that puts kirchhoff 's laws to work for us , too . we call this the application of the fundamental laws . task : find the unknown currents and voltages in this circuit . the steps to a solution involve creating and solving a system of independent equations , label the voltages and currents using the sign convention for passive components . select the independent variable , either $ i $ or $ v $ to produce the simplest equations . write equations using kcl , kvl , or both . make sure every element is represented in at least one equation . solve the system of equations . solve for any remaining unknown voltages and currents you want to know . step 1 : label the schematic to start , it helps to give names to voltages , currents , and nodes , and make a list of what we do and do not know . circuit features and unknowns : $ 5 $ elements $ 3 $ nodes , labeled $ \green a $ , $ \green b $ , and $ \green c $ . $ 3 $ meshes ( inner loops ) . $ 1 $ source voltage , $ v_ { \text s } $ , and $ 2 $ element voltages , $ v_1 $ and $ v_2 $ . $ 1 $ source current , $ i_ { \text s } $ , and $ 3 $ element currents , $ i_1 $ , $ i_2 $ and $ i_3 $ . when assigning polarity to the voltage and current of each element , we use the sign convention for passive components : the current arrow points into the positive voltage end of each resistor . to emphasize there are only three nodes in this circuit , it is redrawn here to highlight the junctions at nodes $ b $ and $ c $ . ( there is an obvious opportunity here to simplify the two parallel resistors , $ 6\ , \omega $ with $ 5\ , \omega $ . we will not do that , because we want to study the general analysis procedure . ) step 2 . select the independent variable at this point we have a choice to make . should the independent variable be voltage $ v $ or current $ i $ ? one good way to make this choice is to compare the number of unknown voltages to unknown currents . there are $ 2 $ unknown voltages , and $ 3 $ unknown currents . if we select voltage as the independent variable , we will have equations with $ 2 $ voltage terms as opposed to $ 3 $ current terms . $ 2 $ is simpler , so voltage will be the independent variable for this problem . step 3 . write independent equations since we have two unknown voltages , we need two independent equations to solve for them . our choice will be a kvl equation around the left-most mesh and a kcl equation at node $ \green b $ . why did i make these particular choices ? i picked the two most interesting features of the circuit . node $ \green b $ has several connections , making it an interesting focal point for the circuit , and the left-most mesh nicely includes the all the remaining circuit elements not fully controlled by node $ \green b $ . admittedly , i used some of my own experience in electronics to anticipate the direction the analysis will take . as you do more problems of this sort , you will build your intuition , too . kvl around the left-most mesh the left-most mesh is the one with the orange circle . we start at the lower left corner of the circuit , where you see the ground symbol , and go clockwise around the mesh adding up voltages . kirchhoff 's voltage law says the sum of element voltages around a loop must add up to zero . $ +v_ { \text { s } } - v_1 - v_2 = 0 $ $ +140 - v_1 - v_2 = 0 $ the $ - $ signs for $ v_1 $ and $ v_2 $ are because we encounter their $ + $ sign first during the clockwise tour around the loop , indicating we will see a voltage drop as we go through the component . kcl at node $ \green b $ we will get our second equation by writing kirchhoff 's current law at node $ \green b $ . one form of kirchhoff 's current law says the currents flowing into a node must equal the currents flowing out of the node . add up the currents flowing into node $ \green b $ , set them equal to the sum of currents flowing out . $ i_1 + i_ { \text s } = i_2 + i_3 $ earlier in step 2. we decided to use $ v_1 $ and $ v_2 $ as the independent variables , so we use ohm 's law to express the unknown currents in terms of voltage and resistance . $ \dfrac { v_1 } { 20\ , \omega } + 18 = \dfrac { v_2 } { 6\ , \omega } + \dfrac { v_2 } { 5\ , \omega } $ after a little rearrangement , we have our system of two equations in two unknowns , $ v_1 + v_2 = 140 $ $ \dfrac { 1 } { 20 } v_1 - \left ( \dfrac { 1 } { 6 } + \dfrac { 1 } { 5 } \right ) v_2 = -18 $ these two equations capture everything going on in our circuit . this is a good time to do a quick check . did every circuit element get a chance to participate in at least one equation ? are any left out ? account for all $ 5 $ elements . steps 4 and 5 - solve have a go at solving this system of equations yourself before looking at the full answer below . find unknown voltages $ v_1 $ and $ v_2 $ , and unknown currents $ i_1 $ , $ i_2 $ , and $ i_3 $ . summary we solved a circuit by direct application of the fundamental laws . our tools were ohm 's law and kirchhoff 's laws . the steps to a solution : label voltages and currents using the sign convention for passive components . select the independent variable , either $ i $ or $ v $ to produce the simplest equations . choose the variable with the fewest unknowns . write equations using kcl , kvl , or both . make sure every element is represented in at least one equation . solve the system of equations for the independent variables ( in this case , $ v_1 $ and $ v_2 $ ) . solve for the other unknowns . $ $ our approach to solving this circuit was solidly based on the fundamental laws , and we got the right answer . but our choice of equations felt somewhat arbitrary . coming up next , we will talk about two efficient and well-organized methods for solving any circuit , the node voltage method , and the mesh current method .
select the independent variable at this point we have a choice to make . should the independent variable be voltage $ v $ or current $ i $ ? one good way to make this choice is to compare the number of unknown voltages to unknown currents .
would n't the current source of 18a affect the voltage across the resistor of 5 ohms , since current is being driven by both the voltage source and the current source of 18a ?
introduction we 've done a few examples of direct application of ohm 's law when we derived equations for series and parallel resistors , a voltage divider , and simplifying a resistor network . now we do an example that puts kirchhoff 's laws to work for us , too . we call this the application of the fundamental laws . task : find the unknown currents and voltages in this circuit . the steps to a solution involve creating and solving a system of independent equations , label the voltages and currents using the sign convention for passive components . select the independent variable , either $ i $ or $ v $ to produce the simplest equations . write equations using kcl , kvl , or both . make sure every element is represented in at least one equation . solve the system of equations . solve for any remaining unknown voltages and currents you want to know . step 1 : label the schematic to start , it helps to give names to voltages , currents , and nodes , and make a list of what we do and do not know . circuit features and unknowns : $ 5 $ elements $ 3 $ nodes , labeled $ \green a $ , $ \green b $ , and $ \green c $ . $ 3 $ meshes ( inner loops ) . $ 1 $ source voltage , $ v_ { \text s } $ , and $ 2 $ element voltages , $ v_1 $ and $ v_2 $ . $ 1 $ source current , $ i_ { \text s } $ , and $ 3 $ element currents , $ i_1 $ , $ i_2 $ and $ i_3 $ . when assigning polarity to the voltage and current of each element , we use the sign convention for passive components : the current arrow points into the positive voltage end of each resistor . to emphasize there are only three nodes in this circuit , it is redrawn here to highlight the junctions at nodes $ b $ and $ c $ . ( there is an obvious opportunity here to simplify the two parallel resistors , $ 6\ , \omega $ with $ 5\ , \omega $ . we will not do that , because we want to study the general analysis procedure . ) step 2 . select the independent variable at this point we have a choice to make . should the independent variable be voltage $ v $ or current $ i $ ? one good way to make this choice is to compare the number of unknown voltages to unknown currents . there are $ 2 $ unknown voltages , and $ 3 $ unknown currents . if we select voltage as the independent variable , we will have equations with $ 2 $ voltage terms as opposed to $ 3 $ current terms . $ 2 $ is simpler , so voltage will be the independent variable for this problem . step 3 . write independent equations since we have two unknown voltages , we need two independent equations to solve for them . our choice will be a kvl equation around the left-most mesh and a kcl equation at node $ \green b $ . why did i make these particular choices ? i picked the two most interesting features of the circuit . node $ \green b $ has several connections , making it an interesting focal point for the circuit , and the left-most mesh nicely includes the all the remaining circuit elements not fully controlled by node $ \green b $ . admittedly , i used some of my own experience in electronics to anticipate the direction the analysis will take . as you do more problems of this sort , you will build your intuition , too . kvl around the left-most mesh the left-most mesh is the one with the orange circle . we start at the lower left corner of the circuit , where you see the ground symbol , and go clockwise around the mesh adding up voltages . kirchhoff 's voltage law says the sum of element voltages around a loop must add up to zero . $ +v_ { \text { s } } - v_1 - v_2 = 0 $ $ +140 - v_1 - v_2 = 0 $ the $ - $ signs for $ v_1 $ and $ v_2 $ are because we encounter their $ + $ sign first during the clockwise tour around the loop , indicating we will see a voltage drop as we go through the component . kcl at node $ \green b $ we will get our second equation by writing kirchhoff 's current law at node $ \green b $ . one form of kirchhoff 's current law says the currents flowing into a node must equal the currents flowing out of the node . add up the currents flowing into node $ \green b $ , set them equal to the sum of currents flowing out . $ i_1 + i_ { \text s } = i_2 + i_3 $ earlier in step 2. we decided to use $ v_1 $ and $ v_2 $ as the independent variables , so we use ohm 's law to express the unknown currents in terms of voltage and resistance . $ \dfrac { v_1 } { 20\ , \omega } + 18 = \dfrac { v_2 } { 6\ , \omega } + \dfrac { v_2 } { 5\ , \omega } $ after a little rearrangement , we have our system of two equations in two unknowns , $ v_1 + v_2 = 140 $ $ \dfrac { 1 } { 20 } v_1 - \left ( \dfrac { 1 } { 6 } + \dfrac { 1 } { 5 } \right ) v_2 = -18 $ these two equations capture everything going on in our circuit . this is a good time to do a quick check . did every circuit element get a chance to participate in at least one equation ? are any left out ? account for all $ 5 $ elements . steps 4 and 5 - solve have a go at solving this system of equations yourself before looking at the full answer below . find unknown voltages $ v_1 $ and $ v_2 $ , and unknown currents $ i_1 $ , $ i_2 $ , and $ i_3 $ . summary we solved a circuit by direct application of the fundamental laws . our tools were ohm 's law and kirchhoff 's laws . the steps to a solution : label voltages and currents using the sign convention for passive components . select the independent variable , either $ i $ or $ v $ to produce the simplest equations . choose the variable with the fewest unknowns . write equations using kcl , kvl , or both . make sure every element is represented in at least one equation . solve the system of equations for the independent variables ( in this case , $ v_1 $ and $ v_2 $ ) . solve for the other unknowns . $ $ our approach to solving this circuit was solidly based on the fundamental laws , and we got the right answer . but our choice of equations felt somewhat arbitrary . coming up next , we will talk about two efficient and well-organized methods for solving any circuit , the node voltage method , and the mesh current method .
$ +v_ { \text { s } } - v_1 - v_2 = 0 $ $ +140 - v_1 - v_2 = 0 $ the $ - $ signs for $ v_1 $ and $ v_2 $ are because we encounter their $ + $ sign first during the clockwise tour around the loop , indicating we will see a voltage drop as we go through the component . kcl at node $ \green b $ we will get our second equation by writing kirchhoff 's current law at node $ \green b $ . one form of kirchhoff 's current law says the currents flowing into a node must equal the currents flowing out of the node .
after the fourth paragraph under `` kcl at node bb '' why did the ohms qualifier disappear ?
introduction we 've done a few examples of direct application of ohm 's law when we derived equations for series and parallel resistors , a voltage divider , and simplifying a resistor network . now we do an example that puts kirchhoff 's laws to work for us , too . we call this the application of the fundamental laws . task : find the unknown currents and voltages in this circuit . the steps to a solution involve creating and solving a system of independent equations , label the voltages and currents using the sign convention for passive components . select the independent variable , either $ i $ or $ v $ to produce the simplest equations . write equations using kcl , kvl , or both . make sure every element is represented in at least one equation . solve the system of equations . solve for any remaining unknown voltages and currents you want to know . step 1 : label the schematic to start , it helps to give names to voltages , currents , and nodes , and make a list of what we do and do not know . circuit features and unknowns : $ 5 $ elements $ 3 $ nodes , labeled $ \green a $ , $ \green b $ , and $ \green c $ . $ 3 $ meshes ( inner loops ) . $ 1 $ source voltage , $ v_ { \text s } $ , and $ 2 $ element voltages , $ v_1 $ and $ v_2 $ . $ 1 $ source current , $ i_ { \text s } $ , and $ 3 $ element currents , $ i_1 $ , $ i_2 $ and $ i_3 $ . when assigning polarity to the voltage and current of each element , we use the sign convention for passive components : the current arrow points into the positive voltage end of each resistor . to emphasize there are only three nodes in this circuit , it is redrawn here to highlight the junctions at nodes $ b $ and $ c $ . ( there is an obvious opportunity here to simplify the two parallel resistors , $ 6\ , \omega $ with $ 5\ , \omega $ . we will not do that , because we want to study the general analysis procedure . ) step 2 . select the independent variable at this point we have a choice to make . should the independent variable be voltage $ v $ or current $ i $ ? one good way to make this choice is to compare the number of unknown voltages to unknown currents . there are $ 2 $ unknown voltages , and $ 3 $ unknown currents . if we select voltage as the independent variable , we will have equations with $ 2 $ voltage terms as opposed to $ 3 $ current terms . $ 2 $ is simpler , so voltage will be the independent variable for this problem . step 3 . write independent equations since we have two unknown voltages , we need two independent equations to solve for them . our choice will be a kvl equation around the left-most mesh and a kcl equation at node $ \green b $ . why did i make these particular choices ? i picked the two most interesting features of the circuit . node $ \green b $ has several connections , making it an interesting focal point for the circuit , and the left-most mesh nicely includes the all the remaining circuit elements not fully controlled by node $ \green b $ . admittedly , i used some of my own experience in electronics to anticipate the direction the analysis will take . as you do more problems of this sort , you will build your intuition , too . kvl around the left-most mesh the left-most mesh is the one with the orange circle . we start at the lower left corner of the circuit , where you see the ground symbol , and go clockwise around the mesh adding up voltages . kirchhoff 's voltage law says the sum of element voltages around a loop must add up to zero . $ +v_ { \text { s } } - v_1 - v_2 = 0 $ $ +140 - v_1 - v_2 = 0 $ the $ - $ signs for $ v_1 $ and $ v_2 $ are because we encounter their $ + $ sign first during the clockwise tour around the loop , indicating we will see a voltage drop as we go through the component . kcl at node $ \green b $ we will get our second equation by writing kirchhoff 's current law at node $ \green b $ . one form of kirchhoff 's current law says the currents flowing into a node must equal the currents flowing out of the node . add up the currents flowing into node $ \green b $ , set them equal to the sum of currents flowing out . $ i_1 + i_ { \text s } = i_2 + i_3 $ earlier in step 2. we decided to use $ v_1 $ and $ v_2 $ as the independent variables , so we use ohm 's law to express the unknown currents in terms of voltage and resistance . $ \dfrac { v_1 } { 20\ , \omega } + 18 = \dfrac { v_2 } { 6\ , \omega } + \dfrac { v_2 } { 5\ , \omega } $ after a little rearrangement , we have our system of two equations in two unknowns , $ v_1 + v_2 = 140 $ $ \dfrac { 1 } { 20 } v_1 - \left ( \dfrac { 1 } { 6 } + \dfrac { 1 } { 5 } \right ) v_2 = -18 $ these two equations capture everything going on in our circuit . this is a good time to do a quick check . did every circuit element get a chance to participate in at least one equation ? are any left out ? account for all $ 5 $ elements . steps 4 and 5 - solve have a go at solving this system of equations yourself before looking at the full answer below . find unknown voltages $ v_1 $ and $ v_2 $ , and unknown currents $ i_1 $ , $ i_2 $ , and $ i_3 $ . summary we solved a circuit by direct application of the fundamental laws . our tools were ohm 's law and kirchhoff 's laws . the steps to a solution : label voltages and currents using the sign convention for passive components . select the independent variable , either $ i $ or $ v $ to produce the simplest equations . choose the variable with the fewest unknowns . write equations using kcl , kvl , or both . make sure every element is represented in at least one equation . solve the system of equations for the independent variables ( in this case , $ v_1 $ and $ v_2 $ ) . solve for the other unknowns . $ $ our approach to solving this circuit was solidly based on the fundamental laws , and we got the right answer . but our choice of equations felt somewhat arbitrary . coming up next , we will talk about two efficient and well-organized methods for solving any circuit , the node voltage method , and the mesh current method .
$ 3 $ meshes ( inner loops ) . $ 1 $ source voltage , $ v_ { \text s } $ , and $ 2 $ element voltages , $ v_1 $ and $ v_2 $ . $ 1 $ source current , $ i_ { \text s } $ , and $ 3 $ element currents , $ i_1 $ , $ i_2 $ and $ i_3 $ . when assigning polarity to the voltage and current of each element , we use the sign convention for passive components : the current arrow points into the positive voltage end of each resistor . to emphasize there are only three nodes in this circuit , it is redrawn here to highlight the junctions at nodes $ b $ and $ c $ .
hi i wan na ask a question about the current source and the voltage source the direction of of i1 , i2 , i3 how can i choose them correctly ?
hi , i 'm monica shah ! what do you work on ? i am a malaria epidemiologist at the centers for disease control and prevention ( cdc ) . initially , i began my career in malaria as a laboratory scientist at cdc , using molecular skills from my background in biochemistry to detect genetic markers of antimalarial drug resistance for surveillance efforts and research studies in sub-saharan africa . while completing my masters in public health , i had the opportunity to apply the epidemiologic and biostatistical methods i learned from my coursework to analyze the laboratory results and explore associations with epidemiological data . this experience along with a work trip to kenya , in which i learned about field work for the first time , sparked my interest in a career as an epidemiologist . as an epidemiologist , i have had the opportunity to work on several malaria field studies in kenya and malawi and contribute to public health work in ghana , uganda , and sierra leone . during one of my first field experiences , i was tasked with training a survey team to conduct a mosquito net census of approximately $ 2500 $ households in malawi . this opportunity was one of many that tied together my epidemiology coursework with the practical realities of study design , implementation , and analysis . i have also gained experience in developing and programming questionnaires for mobile device-based data collection , which involves the use of mobile devices ( such as smartphones , tablets , personal digital assistants , etc . ) to electronically capture information . i have loved designing “ smarter ” questionnaires and training local staff in the countries that we work in to become proficient in these technologies . recently , i have decided to return to school to pursue a doctoral degree in epidemiology , so i am currently a first year graduate student . i guess that being a “ professional ” does not necessarily mean that you know everything there is to know about your field ! instead , it may mean that you have acquired the knowledge and skills necessary to continue asking questions and finding ways to answer them . how did you become interested in chemistry , and what did you study ? i had an incredible chemistry professor in high school who inspired me to pursue further studies in science . in college , i majored in biochemistry and enjoyed learning about how principles of chemistry can explain human metabolism and health conditions . although i was interested in the contents of my core courses in organic chemistry and molecular biology , i found the curriculum ’ s emphasis on advanced calculus and physics challenging . initially , these courses seemed very theoretical , but once i was able to understand their application in chemistry , the concepts became much more interesting ( although , still difficult ! ) . initially , i was interested in pursuing a graduate degree in biochemistry in order to conduct basic science research . however , i gained exposure to public health through a volunteer opportunity as an hiv/aids educator in india and this experience helped me realize that i was more passionate about applied/translational science much more than laboratory research . the scientific training that i gained while studying chemistry has proven to be extremely relevant and useful in my current career as an epidemiologist—particularly skills such as scientific reasoning , hypothesis generating , careful documentation of procedures/results ( i.e . maintaining a laboratory notebook ) and being able to understand the biochemical mechanisms leading to disease . what do you do for fun in your spare time ? i love to bike , travel , and cook . i am also on a quest to find the best mac n cheese in atlanta ! what 's your one piece of advice for people interested in chemistry ? chemistry has applications in many careers , so don ’ t feel limited in scope by the core areas that you study in school . it is also important to gain experience to truly understand how chemistry applies in different settings .
instead , it may mean that you have acquired the knowledge and skills necessary to continue asking questions and finding ways to answer them . how did you become interested in chemistry , and what did you study ? i had an incredible chemistry professor in high school who inspired me to pursue further studies in science . in college , i majored in biochemistry and enjoyed learning about how principles of chemistry can explain human metabolism and health conditions .
during your studies of chemistry during school , what keep you interested in pursuing chemistry ?
hi , i 'm monica shah ! what do you work on ? i am a malaria epidemiologist at the centers for disease control and prevention ( cdc ) . initially , i began my career in malaria as a laboratory scientist at cdc , using molecular skills from my background in biochemistry to detect genetic markers of antimalarial drug resistance for surveillance efforts and research studies in sub-saharan africa . while completing my masters in public health , i had the opportunity to apply the epidemiologic and biostatistical methods i learned from my coursework to analyze the laboratory results and explore associations with epidemiological data . this experience along with a work trip to kenya , in which i learned about field work for the first time , sparked my interest in a career as an epidemiologist . as an epidemiologist , i have had the opportunity to work on several malaria field studies in kenya and malawi and contribute to public health work in ghana , uganda , and sierra leone . during one of my first field experiences , i was tasked with training a survey team to conduct a mosquito net census of approximately $ 2500 $ households in malawi . this opportunity was one of many that tied together my epidemiology coursework with the practical realities of study design , implementation , and analysis . i have also gained experience in developing and programming questionnaires for mobile device-based data collection , which involves the use of mobile devices ( such as smartphones , tablets , personal digital assistants , etc . ) to electronically capture information . i have loved designing “ smarter ” questionnaires and training local staff in the countries that we work in to become proficient in these technologies . recently , i have decided to return to school to pursue a doctoral degree in epidemiology , so i am currently a first year graduate student . i guess that being a “ professional ” does not necessarily mean that you know everything there is to know about your field ! instead , it may mean that you have acquired the knowledge and skills necessary to continue asking questions and finding ways to answer them . how did you become interested in chemistry , and what did you study ? i had an incredible chemistry professor in high school who inspired me to pursue further studies in science . in college , i majored in biochemistry and enjoyed learning about how principles of chemistry can explain human metabolism and health conditions . although i was interested in the contents of my core courses in organic chemistry and molecular biology , i found the curriculum ’ s emphasis on advanced calculus and physics challenging . initially , these courses seemed very theoretical , but once i was able to understand their application in chemistry , the concepts became much more interesting ( although , still difficult ! ) . initially , i was interested in pursuing a graduate degree in biochemistry in order to conduct basic science research . however , i gained exposure to public health through a volunteer opportunity as an hiv/aids educator in india and this experience helped me realize that i was more passionate about applied/translational science much more than laboratory research . the scientific training that i gained while studying chemistry has proven to be extremely relevant and useful in my current career as an epidemiologist—particularly skills such as scientific reasoning , hypothesis generating , careful documentation of procedures/results ( i.e . maintaining a laboratory notebook ) and being able to understand the biochemical mechanisms leading to disease . what do you do for fun in your spare time ? i love to bike , travel , and cook . i am also on a quest to find the best mac n cheese in atlanta ! what 's your one piece of advice for people interested in chemistry ? chemistry has applications in many careers , so don ’ t feel limited in scope by the core areas that you study in school . it is also important to gain experience to truly understand how chemistry applies in different settings .
what do you work on ? i am a malaria epidemiologist at the centers for disease control and prevention ( cdc ) . initially , i began my career in malaria as a laboratory scientist at cdc , using molecular skills from my background in biochemistry to detect genetic markers of antimalarial drug resistance for surveillance efforts and research studies in sub-saharan africa .
what chemicals do you guys used to treat a rare disease ?
old , beautiful and important the ardabil carpet is exceptional ; it is one of the world 's oldest islamic carpets , as well as one of the largest , most beautiful and historically important . it is not only stunning in its own right , but it is bound up with the history of one of the great political dynasties of iran . about carpets carpets are among the most fundamental of islamic arts . portable , typically made of silk and wools , carpets were traded and sold across the islamic lands and beyond its boundaries to europe and china . those from iran were highly prized . carpets decorated the floors of mosques , shrines and homes , but they could also be hung on walls of houses to preserve warmth in the winter . ardabil and a 14th century saint the carpet takes its name from the town of ardabil in north-west iran . ardabil was the home to the shrine of the sufi saint , safi al-din ardabili , who died in 1334 ( sufism is islamic mysticism ) . he was a sufi leader who trained his followers in islamic mystic practices . after his death , his following grew and his descendents became increasingly powerful . in 1501 one of his descendents , shah isma ’ il , seized power , united iran , and established shi ’ a islam as the official religion . the dynasty he founded is known as the safavids . their rule , which lasted until 1722 , was one of the most important periods for islamic art , especially for textiles and for manuscripts . made for a shrine this carpet was one of a matching pair that was made for the shrine of safi al-din ardabili when it was enlarged in the late 1530s . today the ardabil carpet dominates the main islamic art gallery in the victoria and albert museum in london , while its twin is in the la county museum of art . the carpets were located side by side in the shrine . the pile of the carpet is made from wool , rather than silk because it holds dye better . the knot-count of a carpet still directly impacts the value of carpets today ; the more knots per square centimeter , the more detailed and elaborate the patterns can be . the dyes used to color the carpet are natural and include pomegranate rind and indigo . up to ten weavers could have worked on the carpet at any given time . the ardabil carpet has 340 knots per square inch ( 5300 knots per ten centimeters square ) . today , a commercial rug averages 80-160 knots per square inch , meaning that the ardabil carpet was highly detailed . its high knot count allowed for the inclusion of an intricate design and pattern . it is not known whether the carpet was produced in a royal workshop , but there is evidence for court workshop in the 15th and 16th centuries . design and pattern the rich geometric patterns , vegetative scrolls , floral flourishes , so typical of islamic art , reach a fever pitch in this remarkable carpet , encouraging the viewer to walk around and around , trying to absorb every detail of design . that the design of the carpet was not arbitrary or piecemeal , but was well-organized and thoughtful can be seen throughout . considering the immense size of the carpet—10.51m x 5.34m ( 34 ' 6 '' x 17 ' 6 '' ) —this is impressive . a central golden medallion dominates the carpet ; it is surrounded by a ring of multi-colored , detailed ovals . lamps appear to hang at either end . the carpet ’ s border is made up of a frame with a series of cartouches ( rectangular-shaped spaces for calligraphy ) , filled with decoration . the central medallion design is also echoed by the four corner-pieces . art historians have debated the meaning of the two lamps that appear to hang from the medallion . they are of different sizes and some scholars have proposed that this was done to create a perspective effect , meaning that both lamps appear to be the same size when one sat next to the smaller lamp . yet , there is no evidence for the use of this type of perspective in iran in the 1530s , nor does this explain why the lamps were included . perhaps they were included to mimic lamps found in mosques and shrines , helping the viewer to look deeply into the carpet below them and then above them , to the ceiling where similar lamps would have hung , creating visual unity within the shrine . an inscription the ardabil carpet includes a four-line inscription placed at one end . this short poem is vital for understanding who commissioned the carpet and the date of the carpet . the first three lines of poetry reads : except for thy threshold , there is no refuge for me in all the world . except for this door there is no resting-place for my head . the work of the slave of the portal , maqsud kashani . maqsud was probably the court official charged with producing the carpets . by referring to himself as a slave , he may be presenting himself as a humble servant . the persian word for a door can be used to denote a shrine or royal court , so this inscription may imply that the royal court patronized the shrine . the carpets would have probably taken four years to make . the fourth line of the inscription is also important . it provides the date of the carpet , ah 946 . the muslim calendar begins in the year 620 ce when muhammad fled from mecca to medina ; this year is known as the year of the hijra or flight ( in latin anno hegirae ) . ah 946 is equivalent to 1539/40 ce ( the lunar muslim calendar does not exactly match the gregorian calendar , used in the west ) . the design of the ardabil carpet and its skillful execution is a testament to the great skill of the artisans at work in north-west iran in the 1530s . how the carpet came to the v & amp ; a many great treasures from around the world have legally made their way into the collections of western museums . many objects were legally purchased by collectors and museums in the 19th and 20th centuries ; however , many works of art are still illegally exported and sold . british visitors to the shrine in 1843 , noted that at least one carpet was still in situ . approximately thirty years or so later , an earthquake damaged the shrine , and the carpets were sold off . ziegler & amp ; co. , a manchester firm involved in the carpet trade purchased the damaged carpets in iran and “ restored ” them in fashion typical of the late nineteenth century . selections of one carpet were used to repair the other , resulting in a “ complete ” carpet and one lacking a border . vincent robinson and co , a dealer based in london , put the larger carpet up for sale in 1892 and persuaded the v & amp ; a to purchase it for £2000 in march 1893 . the second carpet was secretly sold to an american collector , j.p. getty , who donated it to the la county museum of art in 1953 . unlike the carpet in the v & amp ; a , the carpet in lacma is incomplete . throughout the twentieth century , other pieces of the carpets have appeared on the art market for sale . essay by dr. elizabeth macaulay-lewis additional resources : this carpet at the v & amp ; a on the conservation of the carpet the ardabil carpet at lacma carpets of the islamic world at the metropolitan museum of art 's heilbrunn timeline of art history ellis , charles grant . oriental carpets in the philadelphia museum of art . philadelphia : ( philadelphia museum of art , 1988 ) . erdmann , kurt . oriental carpets : an account of their history , translated by charles grant ellis ( fishguard , wales : crosby , 1976 ) . ​ jon thompson , carpet magic ( london : barbican art gallery , 1983 ) . jon thompson , milestones in the history of carpets ( milan : moshe tabibnia , 2006 ) .
the persian word for a door can be used to denote a shrine or royal court , so this inscription may imply that the royal court patronized the shrine . the carpets would have probably taken four years to make . the fourth line of the inscription is also important .
i know it is also the name of a dark blue colour , but how would one make a dye this colour ?
old , beautiful and important the ardabil carpet is exceptional ; it is one of the world 's oldest islamic carpets , as well as one of the largest , most beautiful and historically important . it is not only stunning in its own right , but it is bound up with the history of one of the great political dynasties of iran . about carpets carpets are among the most fundamental of islamic arts . portable , typically made of silk and wools , carpets were traded and sold across the islamic lands and beyond its boundaries to europe and china . those from iran were highly prized . carpets decorated the floors of mosques , shrines and homes , but they could also be hung on walls of houses to preserve warmth in the winter . ardabil and a 14th century saint the carpet takes its name from the town of ardabil in north-west iran . ardabil was the home to the shrine of the sufi saint , safi al-din ardabili , who died in 1334 ( sufism is islamic mysticism ) . he was a sufi leader who trained his followers in islamic mystic practices . after his death , his following grew and his descendents became increasingly powerful . in 1501 one of his descendents , shah isma ’ il , seized power , united iran , and established shi ’ a islam as the official religion . the dynasty he founded is known as the safavids . their rule , which lasted until 1722 , was one of the most important periods for islamic art , especially for textiles and for manuscripts . made for a shrine this carpet was one of a matching pair that was made for the shrine of safi al-din ardabili when it was enlarged in the late 1530s . today the ardabil carpet dominates the main islamic art gallery in the victoria and albert museum in london , while its twin is in the la county museum of art . the carpets were located side by side in the shrine . the pile of the carpet is made from wool , rather than silk because it holds dye better . the knot-count of a carpet still directly impacts the value of carpets today ; the more knots per square centimeter , the more detailed and elaborate the patterns can be . the dyes used to color the carpet are natural and include pomegranate rind and indigo . up to ten weavers could have worked on the carpet at any given time . the ardabil carpet has 340 knots per square inch ( 5300 knots per ten centimeters square ) . today , a commercial rug averages 80-160 knots per square inch , meaning that the ardabil carpet was highly detailed . its high knot count allowed for the inclusion of an intricate design and pattern . it is not known whether the carpet was produced in a royal workshop , but there is evidence for court workshop in the 15th and 16th centuries . design and pattern the rich geometric patterns , vegetative scrolls , floral flourishes , so typical of islamic art , reach a fever pitch in this remarkable carpet , encouraging the viewer to walk around and around , trying to absorb every detail of design . that the design of the carpet was not arbitrary or piecemeal , but was well-organized and thoughtful can be seen throughout . considering the immense size of the carpet—10.51m x 5.34m ( 34 ' 6 '' x 17 ' 6 '' ) —this is impressive . a central golden medallion dominates the carpet ; it is surrounded by a ring of multi-colored , detailed ovals . lamps appear to hang at either end . the carpet ’ s border is made up of a frame with a series of cartouches ( rectangular-shaped spaces for calligraphy ) , filled with decoration . the central medallion design is also echoed by the four corner-pieces . art historians have debated the meaning of the two lamps that appear to hang from the medallion . they are of different sizes and some scholars have proposed that this was done to create a perspective effect , meaning that both lamps appear to be the same size when one sat next to the smaller lamp . yet , there is no evidence for the use of this type of perspective in iran in the 1530s , nor does this explain why the lamps were included . perhaps they were included to mimic lamps found in mosques and shrines , helping the viewer to look deeply into the carpet below them and then above them , to the ceiling where similar lamps would have hung , creating visual unity within the shrine . an inscription the ardabil carpet includes a four-line inscription placed at one end . this short poem is vital for understanding who commissioned the carpet and the date of the carpet . the first three lines of poetry reads : except for thy threshold , there is no refuge for me in all the world . except for this door there is no resting-place for my head . the work of the slave of the portal , maqsud kashani . maqsud was probably the court official charged with producing the carpets . by referring to himself as a slave , he may be presenting himself as a humble servant . the persian word for a door can be used to denote a shrine or royal court , so this inscription may imply that the royal court patronized the shrine . the carpets would have probably taken four years to make . the fourth line of the inscription is also important . it provides the date of the carpet , ah 946 . the muslim calendar begins in the year 620 ce when muhammad fled from mecca to medina ; this year is known as the year of the hijra or flight ( in latin anno hegirae ) . ah 946 is equivalent to 1539/40 ce ( the lunar muslim calendar does not exactly match the gregorian calendar , used in the west ) . the design of the ardabil carpet and its skillful execution is a testament to the great skill of the artisans at work in north-west iran in the 1530s . how the carpet came to the v & amp ; a many great treasures from around the world have legally made their way into the collections of western museums . many objects were legally purchased by collectors and museums in the 19th and 20th centuries ; however , many works of art are still illegally exported and sold . british visitors to the shrine in 1843 , noted that at least one carpet was still in situ . approximately thirty years or so later , an earthquake damaged the shrine , and the carpets were sold off . ziegler & amp ; co. , a manchester firm involved in the carpet trade purchased the damaged carpets in iran and “ restored ” them in fashion typical of the late nineteenth century . selections of one carpet were used to repair the other , resulting in a “ complete ” carpet and one lacking a border . vincent robinson and co , a dealer based in london , put the larger carpet up for sale in 1892 and persuaded the v & amp ; a to purchase it for £2000 in march 1893 . the second carpet was secretly sold to an american collector , j.p. getty , who donated it to the la county museum of art in 1953 . unlike the carpet in the v & amp ; a , the carpet in lacma is incomplete . throughout the twentieth century , other pieces of the carpets have appeared on the art market for sale . essay by dr. elizabeth macaulay-lewis additional resources : this carpet at the v & amp ; a on the conservation of the carpet the ardabil carpet at lacma carpets of the islamic world at the metropolitan museum of art 's heilbrunn timeline of art history ellis , charles grant . oriental carpets in the philadelphia museum of art . philadelphia : ( philadelphia museum of art , 1988 ) . erdmann , kurt . oriental carpets : an account of their history , translated by charles grant ellis ( fishguard , wales : crosby , 1976 ) . ​ jon thompson , carpet magic ( london : barbican art gallery , 1983 ) . jon thompson , milestones in the history of carpets ( milan : moshe tabibnia , 2006 ) .
the knot-count of a carpet still directly impacts the value of carpets today ; the more knots per square centimeter , the more detailed and elaborate the patterns can be . the dyes used to color the carpet are natural and include pomegranate rind and indigo . up to ten weavers could have worked on the carpet at any given time .
: ) what exactly is `` pomegrante rind '' dye , and what was used to make it ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions .
what conditions must be met to be awarded the `` intro to js : drawing & animation mastery badge '' ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages !
at the end of the review , paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; why add this.numpages = 0 ; ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death .
back in the last section we learned how to create arrays of objects , but how would that work with a constructors and methods ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages !
ca n't we just say : paperback.prototype = new book ( ) ; instead of : paperback.prototype = object.create ( book.prototype ) ; ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages !
book.prototype.readitall ) can now be applied to a paperback object ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death .
what would be the most efficient way to make a pixel drawing function ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type .
and what does .object do in javascript ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later .
on the review why do we have to declare this.numpages = 0 , wo n't `` this '' just recognize the current object number of pages and use that ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later .
is there a way to delete an instance of an object ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch .
what if the `` parent '' object has more than one prototype ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' .
how do we distinguish between prototypes when creating prototypes for the child objects ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) .
why must you put the 'this ' inside the ( ) 's when you run a x.call ( ) command ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions .
and what exactly is 'this ' stand for ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it !
when we write something like var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; are we making another instance of book but with extra features or are we making a new constructor function ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword .
var book = function ( title , stars , author , color ) { this.title = title ; this.stars = stars ; this.author = author ; this.color = color ; } ; var books = [ var harrypotter = new book { `` harry potter '' , 5 , `` j.k. rowling '' , color ( 204 , 0 , 255 ) } } anybody know what i 'm doing wrong ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages .
is it correct to say the constructor function defines the class , and then when `` new '' is used with a variable , we create an object from the class ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' .
i decided to start converting the structure to be object oriented in order to keep things more organised but now i am in a dilemma : how far should i go ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it !
var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; why not just put the cover attribute inside the call function parameters like var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages , cover ) ; } ; or is there a set number of elements you can put into a funtion ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them .
var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author in the above , why is isaac asimov in quotes while robot dreams is n't ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword .
in the definition of the burn function , why is this.numpages passed 0 ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword .
why is `` this.numpages = 0 ; '' added at the end of the burn function ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages !
what is the use of > prototype < ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' .
how can i create an array of objects with a object creator function ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword .
can you pass objects to a function ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages !
how.the program interpret `` book.readitall ( ) ; '' and why it is not written as book.read.it.all another question is that i see that the word `` burn '' is not defined in this command : `` paperback.prototype.burn '' therefore , should it be a variable first ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type .
why the official processingjs documentation uses a different way to define classes ( class keyword ) , functions ( we can define returning value type directly ) and variables ( ex : int for integers ) ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages !
instead of paperback.prototype.burn = function ( ) { blah } why not this.burn = function ( ) { blah } inside of the paperback object ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' .
can sibling object types inherit from one another ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods .
why does 'this ' not work to assign conditions that can be used in if statements ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages !
in the paperback burn function/method above , why did you have this.numpages = 0 in the final line of code ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type .
can you move your draw method definition to be just under the constructor ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions .
what is the value for `` x '' in `` this.x = x '' ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions .
what is the equivalent of calling super.functionname ( ) in ka processing js ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them .
what is the difference between println ( ) and text ( ) ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages !
ca n't we simply write paperback=object.create ( book ) ; instead of paperback.prototype=object.create ( book.prototype ) ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages !
are n't objects like functions ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally .
is the word changed just because it 's a function that is applied to a prototype , rather than a single object ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions .
and what is an 'argument ' ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it !
how could i make my new constructor function ( paperback ) only inherit some of ( books ) the other object 's methods ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages !
can somebody give me a easier definition of prototype ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword .
what does `` e.apply is not an function '' mean ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook .
and one question how am i going to javascript in html and css ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
`` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages !
at flower grower i get an error called e.apply is not a function what to do ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages !
on the smileyface challenge , i am stuck on part 3 where we have to add this- smileyface.prototype.draw = function ( ) { } ; var face = new smileyface ( 200 , 300 ) ; face.draw ( ) ; what do i put in the draw function brackets ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later !
can anybody help me out with how to make a functional text box ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages !
at the bottom of this article , what 's the meaning of `` this.numpages = 0 ; '' in `` paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; '' ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' .
can i extend inherited methods like i can extend inherited object constructors ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages !
paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; why give this.numpages a value '0 ' to begin with ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' .
how do you override functions in the child object ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword .
var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , autor , numpages , color ) ; } ; asuming that color was a this variable in the book object type ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages !
when creating a sub-object like paperback under book , why is it necessary to create both constructor code for paperback based on book as well as define the prototype of paperback based on the prototype of book ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it !
when building the constructor for paperback , why does it not automatically inherit the methods contained in book ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet !
`` ) ; } ; what is the reason for the following line of code ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions .
when making a construction , what does ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages !
can you have multiple inheritances with many different objects so that one object may be a 'grandparent ' to another object ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions .
what are the uses of this.//argument=//argument ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image .
i want game character to jump in curvy path making a `` c '' .how should i make it , give me the codings ?
this is a review of what we covered in this tutorial on object-oriented design . when we create programs , we often find that we want to create many different objects that all share similar properties - like many cats , that have slightly different fur color and size , or many buttons , with different labels and positions . we want to be able to say `` this is generally what a cat is like '' and then say `` let 's make this specific cat , and this other cat , and they 'll be similar in some ways and different in a few ways as well . '' in that case , we want to use object-oriented design to define object types and create new instances of those objects . to define an object type in javascript , we first have to define a `` constructor function '' . this is the function that we 'll use whenever we want to create a new instance of that object type . here 's a constructor function for a book object type : var book = function ( title , author , numpages ) { this.title = title ; this.author = author ; this.numpages = numpages ; this.currentpage = 0 ; } ; the function takes in arguments for the aspects that will be different about each book - the title , author , and number of pages . it then sets the initial properties of the object based on those arguments , using the this keyword . when we use this in an object , we are referring to the current instance of an object , referring to itself . we need to store the properties on this to make sure we can remember them later . to create an instance of a book object , we declare a new variable to store it , then use the new keyword , followed by the constructor function name , and pass in the arguments that the constructor expects : var book = new book ( `` robot dreams '' , `` isaac asimov '' , 320 ) ; we can then access any properties that we stored in the object using dot notation : println ( `` i loved reading `` + book.title ) ; // i loved reading robot dreams println ( book.author + `` is my fav author '' ) ; // `` isaac asimov '' is my fav author let 's contrast this for a minute , and show what would have happened if we did n't set up our constructor function properly : var book = function ( title , author , numpages ) { } ; var book = new book ( `` little brother '' , `` cory doctorow '' , 380 ) ; println ( `` i loved reading `` + book.title ) ; // i loved reading undefined println ( book.author + `` is my fav author '' ) ; // undefined is my favorite author if we pass the arguments into the constructor function but do not explicitly store them on this , then we will not be able to access them later ! the object will have long forgotten about them . when we define object types , we often want to associate both properties and behavior with them - like all of our cat objects should be able to meow ( ) and eat ( ) . so we need to be able to attach functions to our object type definitions , and we can do that by defining them on what 's called the object prototype : book.prototype.readitall = function ( ) { this.currentpage = this.numpages ; println ( `` you read `` + this.numpages + `` pages ! `` ) ; } ; it 's like how we would define a function normally , except that we hang it off the book 's prototype instead of just defining it globally . that 's how javascript knows that this is a function that can be called on any book object , and that this function should have access to the this of the book that it 's called on . we can then call the function ( which we call a method , since it 's attached to an object ) , like so : var book = new book ( `` animal farm '' , `` george orwell '' , 112 ) ; book.readitall ( ) ; // you read 112 pages ! remember , the whole point of object-oriented design is that it makes it easy for us to make multiple related objects ( object instances ) . let 's see that in code : `` ` var pirate = new book ( `` pirate cinema '' , `` cory doctorow '' , 384 ) ; var giver = new book ( `` the giver '' , `` lois lowry '' , 179 ) ; var tuck = new book ( `` tuck everlasting '' , `` natalie babbit '' , 144 ) ; pirate.readitall ( ) ; // you read 384 pages ! giver.readitall ( ) ; // you read 179 pages ! tuck.readitall ( ) ; // you read 144 pages ! `` ` that code gives us three books that are similar - they all have the same types of properties and behavior , but also different . sweet ! now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death . they 're both mammals , and that means they share a lot in common , even if they 're also different . in that case , we want to use the idea of object inheritance . an object type could inherit properties and behavior from a parent object type , but then also have its own unique things about it . all the cats and dogs could inherit from mammal , so that they would n't have to invent eat ( ) ing from scratch . how would we do that in javascript ? let 's go back to our book example , and say that book is the `` parent '' object type , and we want to make two object types that inherit from it - paperback and ebook . a paperback is like a book , but it has one main thing different , at least for our program : it has a cover image . so , our constructor needs to take four arguments , to take in that extra info : var paperback = function ( title , author , numpages , cover ) { // ... } now , we do n't want to have to do all the work that we already did in the book constructor to remember those first three arguments - we want to take advantage of the fact that the code for that would be the same . so we can actually call the book constructor from the paperback constructor , and pass in those arguments : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; // ... } ; we still need to store the cover property in the object though , so we need one more line to take care of that : var paperback = function ( title , author , numpages , cover ) { book.call ( this , title , author , numpages ) ; this.cover = cover ; } ; now , we have a constructor for our paperback , which helps it share the same properties as books , but we also want our paperback to inherit its methods . here 's how we do that , by telling the program that the paperback prototype should be based on the book prototype : paperback.prototype = object.create ( book.prototype ) ; we might also want to attach paperback-specific behavior , like being able to burn it , and we can do that by defining functions on the prototype , after that line above : paperback.prototype.burn = function ( ) { println ( `` omg , you burnt all `` + this.numpages + `` pages '' ) ; this.numpages = 0 ; } ; and now we can create a new paperback , read it all , and burn it ! `` ` var calvin = new paperback ( `` the essential calvin & amp ; hobbes '' , `` bill watterson '' , 256 , `` http : //ecx.images-amazon.com/images/i/61m41hxr0zl.jpg '' ) ; calvin.readitall ( ) ; // you read 256 pages ! calvin.burn ( ) ; // omg , you burnt all 256 pages ! `` ` ( well , we 're not really going to burn it , because that 's an amazing book , but perhaps if we were stuck in a glacial desert and desperate for warmth and about to die . ) and now you can see how we can use object-oriented design principles in javascript to create more complex data for your programs and model your program worlds better .
now , if you think about the world , cats and dogs are different types of objects , so you 'd probably create different object types for them if you were programming a cat and a dog . a cat would meow ( ) , a dog would bark ( ) . but they 're also similar- both a cat and dog would eat ( ) , they both have an age , and a birth , and a death .
would you as a programmer be in legal trouble even though you were only writing numbers , shapes , and text yourself ?