<html>
<head>
<meta name="description" content="Inheritance.js 0.1.1 Sample: Create New Object Definition">
<meta charset="utf-8">
<title>Inheritance.js 0.1.1 Sample: Create New Object Definition</title>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css"/>
<script src="https://dl.dropboxusercontent.com/u/262650966/inheritance.js/0.3.2/inheritance.min.js"></script>
</head>
<body>
<h1>Inheritance.js 0.3.2 Sample: Create New Object Definition</h1>
<p>Open the "JavaScript" and "Console" panels for details.</p>
</body>
</html>
body {
padding: 50px;
}
// =============================================== //
// Inheritance.js 0.3.2 Sample: //
// Create a New Object Definition (I.E. "Class") //
// =============================================== //
// Mixins are assumed to be simple objects and you are highly encouraged
// to keep them that way given what a mixin is. However, mixins are not
// required to be simple objects.
var MyMixin0 = {
mixin0Attr: "Mixin 0 Attribute Value"
};
var MyMixin1 = {
mixin1Attr: "Mixin 1 Attribute Value",
mixin1Func: function() {
if (typeof this.protoAttr0 !== 'undefined') {
console.log("Mixin 1 function hit!");
console.log(" this.protoAttr0 = '" + this.protoAttr0 + "'");
}
}
};
var MyMixin2 = {
mixin2Func: function() {
console.log("Mixin 2 function hit!")
}
};
var MyNewObject = ObjectDefinition.create({
mixins: [
MyMixin0,
MyMixin1,
MyMixin2
],
static: { // These attributes will NOT be inherited by any child object definitions.
staticAttr0: 42,
staticAttr1: 4242,
staticFunc0: function(param0) {
alert("MyNewObject.staticFunc0 hit!");
}
},
protoAttr0: null,
protoAttr1: "Fish fingers and custard",
protoAttr2: {
attr0: 17,
attr1: null
},
protoAttr3: [ 'val0', 'val1', 'val2' ],
// This function is NOT required, but it acts as the constructor
// for object creation if is present.
ctor: function MyNewObject(id) {
console.log("MyNewObject.ctor hit!");
this.protoAttr0 = id;
},
func0: function() {
console.log("MyNewObject.func0 hit!");
},
func1: function(toPrint) {
console.log(toPrint);
}
});
console.log("MyNewObject.name = '" + MyNewObject.name + "'");
console.log("MyNewObject.staticAttr0 = '" + MyNewObject.staticAttr0 + "'");
console.log("MyNewObject.staticAttr1 = '" + MyNewObject.staticAttr1 + "'");
MyNewObject.staticFunc0();
var obj = new MyNewObject(4400);
console.log("obj.protoAttr0 = '" + obj.protoAttr0 + "'");
console.log("obj.protoAttr1 = '" + obj.protoAttr1 + "'");
console.log("obj.protoAttr2.attr0 = '" + obj.protoAttr2.attr0 + "'");
console.log("obj.protoAttr2.attr1 = '" + obj.protoAttr2.attr1 + "'");
console.log("obj.protoAttr3 = '" + obj.protoAttr3 + "'");
obj.func0();
obj.func1("This is what I want printed.");
console.log("obj.mixin0Attr = '" + obj.mixin0Attr + "'");
console.log("obj.mixin1Attr = '" + obj.mixin1Attr + "'");
obj.mixin1Func();
obj.mixin2Func();
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |