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
// Public | |
function Constructor(...) { | |
this.membername = value; | |
} | |
Constructor.prototype.membername = value; | |
// Private | |
function Constructor(...) { | |
var that = this; | |
var membername = value; |
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
/* Pvt.js - JavaScript Private Instance Members | |
* By Adam Crabtree http://noderiety.com/ | |
* MIT Licensed. | |
*/ | |
/** | |
* Generate a private member store | |
* @returns {function} The private member accessor function | |
*/ | |
function Pvt() { |
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
/* Privates.js - Simple JavaScript Inheritance With Inheritable Private Variables | |
* By Adam Crabtree http://noderiety.com/ | |
* MIT Licensed. | |
* | |
* Forked from: | |
* Simple JavaScript Inheritance | |
* By John Resig http://ejohn.org/ | |
* http://ejohn.org/blog/simple-javascript-inheritance/ | |
* Inspired by base2 and Prototype | |
*/ |
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
// Utilize a closure to keep the private members private | |
var Person = (function() { | |
// Generate a private instance member accessor function "pvt" | |
var pvt = Pvt(), | |
// private static member | |
species = "Homo sapien"; | |
var Self = function(isDancing) { |
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
// Class.extend takes a function that returns the options object | |
// it is passed the accessor function generated in the Pvt.js example above | |
var Person = Class.extend(function(pvt) { | |
// private static member | |
var species = "Homo sapien"; | |
return { | |
init: function(isDancing) { | |
// pvt(this).invisible === undefined |
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
// NOT AN APPLICATION, I JUST WANTED TO TAKE YOUR TEST. =) | |
// 1: how could you rewrite the following to make it shorter? | |
if (foo) { | |
bar.doSomething(el); | |
} else { | |
bar.doSomethingElse(el); | |
} | |
// ANSWER |
NewerOlder