Skip to content

Instantly share code, notes, and snippets.

View pycraft114's full-sized avatar

ChanWoo Park pycraft114

View GitHub Profile
@Component()
class ContactsApp implements OnInit{
firstName: string = 'Super';
lastName: string = 'Cat';
constructor(private http: Http) {}
ngOnInit() {
this.http.get('/name/mouse')
@Component({
template: `
<h1>Hello! {{firstName}} {{lastName}}</h1>
<button (click)="changeName()">Change name</button>
`
})
class MyApp {
firstName:string = 'Super';
lastName:string = 'Cat';
@pycraft114
pycraft114 / pureExample.js
Created August 13, 2017 06:36
why reducers should be pure
//initial state
const data = {
id : null,
password : null
};
function reducer(state = data, action){
switch(action.type){
case ID_MODIFIED:
return {...state, id : action.payload };
@pycraft114
pycraft114 / noPureExample.js
Created August 13, 2017 06:34
why reducers should be pure
//initial state
const data = {
id : null,
password : null
};
export default function(state = data, action){
switch(action.type){
case ID_MODIFIED:
state.id = action.payload;
@pycraft114
pycraft114 / sharingExample2.js
Created August 13, 2017 06:30
Call by sharing example 2
function test(a, b){
a.value = 70;
b = b * 20;
}
var firstArg = { age: 10 };
var secondArg = 30;
test(firstArg, secondArg);
@pycraft114
pycraft114 / sharingExample1.js
Last active August 13, 2017 06:29
Call by sharing example 1
function test(a, b){
a = { something : "this is something" };
b.hello = "no greetings for you";
}
var firstArg = { hello : "hello world" };
var secondArg = { hello : "hello world" };
test(firstArg, secondArg);
function Health(name,lastname){
this.name = name;
this.lastname = lastname;
}
var a = Health("chanwoo","park"); //return값이 없기때문에 a는 언디파인드, 윈도우에 네임 변수를 생성했기때문에 'chanwoo'출력
console.log(name);
var allFuntions = {
function Health(name,lastname){
this.name = name;
this.lastname = lastname;
}
var a = Health("chanwoo","park"); //return값이 없기때문에 a는 언디파인드, 윈도우에 네임 변수를 생성했기때문에 'chanwoo'출력
console.log(name);
@pycraft114
pycraft114 / assignment.js
Created January 7, 2017 07:30
assignment
//--------------Returns odd numbers---------------------------------------------
function printOdd(number){
var i = 0;
var oddNum = [];
while (i <= number){
if (i % 2 === 1){
oddNum.push(i);
i++;
}else {