Last active
August 29, 2015 13:56
-
-
Save yajd/9286086 to your computer and use it in GitHub Desktop.
_js-tutorial-CustomObjectsAndPrototype - I finally learned and understood custom objects AND prototype. Start with learning prototype in this tutorial "[The prototype object of JavaScript](http://www.javascriptkit.com/javatutors/proto.shtml)" and when you get to the "[Creating custom objects in JavaScript](http://javascriptkit.com/javatutors/obj…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //dummy just see the description | |
| //i had one question, on the final page of the prototype tut (4th page) | |
| //create dummy object | |
| function dummy(){ | |
| } | |
| //Create custom property | |
| function dummyproperty(){ | |
| } | |
| //Create custom method | |
| function dummymethod(){ | |
| } | |
| dummy.prototype.prop=dummyproperty | |
| dummy.prototype.method=dummymethod | |
| //tut author says this example above "I'll quickly demonstrate the concept by first creating a "dummy object", and using the prototype object- and only this object- to equip the dummy object with properties and methods:" | |
| //however dummyproperty and dummymethod are both object creaters so now dummy.dummyproperty is instance of dummyproperty. to set a property i would think you would do this: | |
| dummy.prototype.propMyWay = 'blah'; //if you set blah to a function with return value than that is a method i would think | |
| //that was my only question after reading the two tuts |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually I have a second question now. What if you put a return value in the create dummy object function? To set props on the object you have to use this. And object methods only have returns. So what if you put a return and some value in the custom object creation function?