Last active
August 18, 2017 09:47
-
-
Save tonystaark/d9e46f9d470c60ab2a08eb90d25c73ac to your computer and use it in GitHub Desktop.
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
If you want to clear something after you insert an input value; set inputtext.value = '' | |
If you want elements like buttons/images to appear on different line in HTML, <div> to separate into lines | |
If you want to change certain index, you can access it like changeTodoPositionInput.value but .value will return string; but you can do .valueAsNumber, to make it number | |
changeTodo: function(){ | |
var changeTodoPositionInput = document.getElementById('changeTodoPositionInput') | |
var changeTodoTextInput = document.getElementById('changeTodoTextInput') | |
todoList.changeTodo(changeTodoPositionInput.valueAsNumber, changeTodoTextInput.value) | |
} | |
One method of listing <ul><li></li></ul> | |
document.querySelector(''). Create <ul></ul> in HTML, declare var in console (e.g. var ul = document.querySelector('ul'))if hover over it in console, it will highlight | |
document.createElement(''). for e.g. var li = document.createElement('li'). | |
then ul.appendChild('li') |
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 (let i of array) - value | |
for (let i in array) - index | |
************** | |
This when console.log(obj of any array) will return getIndexBy; | |
Array.prototype.getIndexBy = function (name, value) { | |
for (var i = 0; i < this.length; i++) { | |
if (this[i][name] === value) { | |
return i | |
} | |
} | |
return 'No such value' | |
} | |
Instead, we can declare the enum to false; | |
Object.defineProperty(Array.prototype, 'getIndexBy', { | |
enumerable: false, | |
value: function (name, value) { | |
for (var i = 0; i < this.length; i++) { | |
if (this[i][name] === value) { | |
return i | |
} | |
} | |
} | |
}) | |
***Arguments vs parameters*** | |
The formal parameter is what's given in the function declaration/definition/prototype, | |
the actual argument is what's passed when calling the function, an instance of a formal parameter | |
int foo(int x, int y) { -> paramaters | |
... | |
} | |
foo(5, z); -> 5 and z are the actual arguments | |
***forEach** | |
[1,2,3].forEach(function(){ | |
console.log('hi') | |
}) | |
= forEach([1,2,3], function(){ | |
console.log('hi') | |
}) | |
**function within function** | |
function a(){ | |
return 'a' | |
} | |
//if u do this, you will get 'undefined' | |
function b(){ | |
a() | |
} | |
//But if you do this, you will get the result | |
functon b(){ | |
return a() | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment