Skip to content

Instantly share code, notes, and snippets.

@projektorius96
Last active July 26, 2019 21:27
Show Gist options
  • Save projektorius96/11b6c786aea8baace1ae198844879bec to your computer and use it in GitHub Desktop.
Save projektorius96/11b6c786aea8baace1ae198844879bec to your computer and use it in GitHub Desktop.
Object_prototype_constructor_example1
// Constructor function for myObj
function myObj(firstValue, secondValue, thirdValue, undefined) {
this.firstKey = firstValue; // disabled due null
this.secondKey = secondValue; // second parameter is enabled; all the rest are disabled in console output;
this.thirdKey = thirdValue; // disabled due null;
this.nKey = undefined; // disabled due undefined;
}
// Create a myObject; Object Instance name ::after keyword "new" must match name of the function constructor name defined above!
var userInput = new myObj("Index1userA", "JavaScript", "Index3userC", "Index4userD"); /* Basically, what User1 inputs inside parantheses
by changing one of the parameters of myObj object instance; */ /*
parameters inside paranthesis of instance object myObj matches parameters parallely defined inside constructor function parantheses. */
// Display Index2userB or anything else what would be overwritten inside Object Instance instead of Index2UserB by UserB
console.log("My user name is " + userInput.secondKey);
// Console output: My user name is JavaScript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment