Skip to content

Instantly share code, notes, and snippets.

@csalzman
Created January 4, 2017 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csalzman/1e02380398cc8f4a5a43c4d630cd09b1 to your computer and use it in GitHub Desktop.
Save csalzman/1e02380398cc8f4a5a43c4d630cd09b1 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
/*
Walking through this page as a tutorial on how Javascripts object model works:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Details_of_the_Object_Model#Class-Based_vs._Prototype-Based_Languages
*/
//Function for Employee creates a constructor for Employee objects
function Employee() {
this.name = "";
this.dept = "General";
this.title = "";
}
//Manager is going to inherit from Employee and add a reports property
function Manager() {
Employee.call(this);
this.reports = [];
//Setting the title property that Employee setup
this.title = "Manager";
}
//***I am unsure what this does.***
Manager.prototype = Object.create(Employee.prototype);
//Create an instance of an object using the Manager constructor
var mintedManager = new Manager();
document.write(mintedManager.title);
</script>
@csalzman
Copy link
Author

csalzman commented Jan 4, 2017

@hypomodern I thanked you on twitter too, but publicly (on this gist that will probably die someday in a gist purge) thank you!

@keller, thanks! Your object literal example makes a lot more sense to me given how its used in this example. It's helpful to understand the options!

"It feels to me like it's trying to trick devs into thinking it's like classical inheritance, which they successfully do trick devs into being confused" I've really really been feeling this as I'm learning about this. I'd actually started looking into it after reading a bit about classes in es6 and wondering what was making them work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment