prop functor

by Kaleb Hornsby

HTML

<script src="//rawgit.com/es-shims/es5-shim/master/es5-shim.js"></script>
<script src="//rawgit.com/es-shims/es5-shim/master/es5-sham.js"></script>
<script src="//rawgit.com/paulmillr/es6-shim/master/es6-shim.js"></script>
<script src="//rawgit.com/paulmillr/es6-shim/master/es6-sham.js"></script>

JavaScript

function Prop(value) {
    function prop(newValue) {
        if(!arguments.length) return value;
        value = newValue;
        return this;
    }
    return Object.setPrototypeOf(prop, Prop.prototype);;
}
Prop.prototype = Object.create(Function.prototype);
Prop.prototype.toJSON = function() {
    return this();
}

var p = new Prop('test');
alert(p.toJSON())
console.assert(p.toJSON() == 'test', 'prop can access prototype methods')