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
| license: MIT |
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
| //Pseudoclassical Instantiation Pattern | |
| //only properties are needed inside function body | |
| var Box = function(){ | |
| this.width = w; | |
| this.depth = d; | |
| this.height = h; | |
| this.state = 'open'; | |
| //'generator' automatically returns this. | |
| } | |
| //attach methods to 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
| //Prototypal Instantiation Pattern Version one-using 'prototype' | |
| var Box = function(w, d, h){ | |
| //uses Object.create to create attach to the object's prototype | |
| let boxObj = Object.create(Box.prototype); | |
| //**one could also link a seperate object containing methods like such | |
| //let boxObj = Object.create(Box.containerMethods); | |
| //create all properties associated with object | |
| boxObj.width = w; | |
| boxObj.depth = d; | |
| boxObj.height = h; |
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
| //Functional instantiation method, clear and easy to follow but calls new functions each time it is invoked | |
| var Box = function(w, d, h){ | |
| let boxObj = {}; | |
| boxObj.width = w; | |
| boxObj.depth = d; | |
| boxObj.height = h; | |
| boxObj.open = 'open' | |
| //methods associated with new Object and created(defined) inside the function body | |
| //they refer directly to the properties created above. | |
| boxObj.openBox = function(){ |
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
| /* | |
| Instantiation Patterns are a manner in which to organize methods and properties associated with an object and create | |
| repeatable versions of this object, or object class. There are four methods to instatiate a constructor object: | |
| Functional, Functional Shared, Prototypal and Pseudoclassical. | |
| */ |
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
| /* global $ _ opspark */ | |
| $(document).ready(function() { | |
| $.getJSON('data.json', function (data) { | |
| // YOUR CODE BELOW HERE // | |
| // uncomment this to inspect all available data; delete when done // | |
| // console.log(data); | |
| // EXAMPLE: Looping over top rated recordings; replace with your code // | |
| // let topRated = data.discography.topRated; |
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
| var myArr = [1,2,3,4,5,6,7,8,6,7,8,6]; | |
| //last with all the safeties using a for loop | |
| last = function last(arr, number){ | |
| var newArr = []; | |
| if(!Array.isArray(arr)){ | |
| return []; | |
| }else if(isNaN(number) || number === undefined ){ | |
| return arr[arr.length - 1]; | |
| }else if(number < 0){ | |
| return newArr; |
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
| //takes any number of objects and creates one unified object. | |
| _.extend1 = (...objects) =>{ | |
| const target = objects[0]; | |
| _.each(objects, (obj, i, objects) =>{ | |
| if(i === 0)return; | |
| _.each(obj,( val, key, obj)=>{ | |
| target[key] = val; | |
| }); | |
| }); |
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
| /*literally does everything... takes a collection, a call-back | |
| function and a starting state(this could be a number, ) | |
| */ | |
| _.reduce = function(collection, fn, seed){ | |
| var prevResult = seed; | |
| if(seed === undefined) seed = collection[0], prevResult = 1; | |
| _.each(collection, function(el, i, collection){ | |
| prevResult = fn(prevResult, el, i); | |
| }); | |
| return prevResult; |
NewerOlder