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 |
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
// 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
/* 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
/* 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
// 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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
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
Function.prototype.makeCtor = function() { | |
function ctor() { | |
if (!(this instanceof arguments.callee)) { | |
return new (arguments.callee.bind.apply(arguments.callee,Array.prototype.concat.apply([null],arguments))); | |
} else { | |
that.apply(this,arguments); | |
} | |
}; | |
return (Function('var that = this; return '+ctor.toString().replace(ctor.name, this.name))).call(this); | |
} |
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
// For context on difficulties of subclassing Array: | |
// See, http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/ | |
var sandbox = {}; | |
require('vm').createScript('SubArray = Array').runInNewContext(sandbox); | |
var SubArray = sandbox.SubArray; | |
console.log(SubArray); | |
SubArray.prototype.__proto__ = { | |
__proto__: Array.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
// Copyright 2006-2008 the V8 project authors. All rights reserved. | |
// Redistribution and use in source and binary forms, with or without | |
// modification, are permitted provided that the following conditions are | |
// met: | |
// | |
// * Redistributions of source code must retain the above copyright | |
// notice, this list of conditions and the following disclaimer. | |
// * Redistributions in binary form must reproduce the above | |
// copyright notice, this list of conditions and the following | |
// disclaimer in the documentation and/or other materials provided |
OlderNewer