View methods-&-properties.js
// ---
// don't think about functions in objects just yet
// only string, numbers, ...
// ---
let obj = {
p: "roperty",
m: function ethod() {
console.log(this.p)
}
View objects-vs-arrays.js
// ----- objects vs arrays -----
// run in python tutor
function toObject(arr) {
var rv = {};
for (var i = 0; i < arr.length; ++i)
if (arr[i] !== undefined) rv[i] = arr[i];
delete rv[1]
arr.splice(1, 1)
return rv;
View cooool-cloosures.js
// https://goo.gl/JHrzXs
function cooool(num) {
function func_1() {
num++;
};
function func_2() {
console.log(num);
};
View state-store-starter.js
var store = {
debug: true,
nextID: 0,
state: {},
create (newArtist) {
if (this.debug) console.log('created new artist: ' + newArtist);
// create
// call to backend
},
read_one (id) {
View bind-arrow-bad.js
let controller = {
logic: {
add_async: function(num_1, num_2, cb) {
let result = num_1 + num_2;
if(typeof result == "number") {
cb(null, result);
} else {
cb(result);
}
}
View call-bind-construct-this.js
function learning_context(arg) {
console.log(arg)
console.log(this.prop)
}
let bound_context = {
prop: "bound"
}
let call_context = {
View constructor-experiment.js
function experimental_model(_name, is_new) {
if (is_new) {
this.next_id = 0;
this.name = _name;
this.DB = {};
} else {
let new_obj = Object.create(experimental_model.prototype)
new_obj.nextId = 0; // hasOwnProperty -> true
View binding-model.js
// all functions use the "this" key word
function create (new_value) {}
function read_one (ID) {}
function read_all () {}
function update (ID, new_value) {}
function remove (ID) {}
function binding_factory (instance_object) {
return {
create: create.bind(instance_object),
View basic-call.js
function contexting() {
console.log(this)
console.log(this.name)
}
let marta_context = {
name: "marta"
}
let jake_context = {