Function & Object

Function 

특정 코드를 다시 사용할 수 있도록 코드를 묶어두는 방법, 코드의 집합

Parameter(매개변수) : function으로 전달되는 변수

argument(인자) :funtion에서 넘겨 받은 특정값

 

JavaScript의 return은 현재 Function을 종료하고 그 값을 반환함.

 

genRadiusLayer = (x, y, w, h, n) ->
	layer = new Layer
		x: x
		y: y
		name : n
		width: w,
		height: h,
		borderRadius: '10px'
	return layer

genlistLayer = (x, y, n) ->
	layers = []

	for i in [0...n]
		layerA = genRadiusLayer(120*i, y, 100, 100, "Layer"+i)
		layers.push(layerA)
		print(layers[i].name)

	return layers



# genlistLayer = (x, y, n) ->
# 	layers = []
# 	for i in [1..n]
# 		layer = new Layer
# 			name : "layer"+n
# 			x: (x+10)*i
# 			y: y
# 			width : 100
# 			height : 100
# 		layers.push(layer)
# 	return layers
#
layersA = genlistLayer(100,100,10)
layersB = genlistLayer(100,240,10)
layersA[2].backgroundColor="red"
layersB[5].backgroundColor="red"

차주 진행 내용

Array Object 자바스크립트 기반

 

genRadiusLayer = (x, y, w, h, n) ->
	layer = new Layer
		x: x
		y: y
		name : n
		width: w,
		height: h,
		borderRadius: '10px'
	return layer

genlistLayer = (x, y, n) ->
	layers = []

	for i in [0...n]
		layerA = genRadiusLayer(120*i, y, 100, 100, "Layer"+i)
		layers.push(layerA)
		print(layers[i].name)

	return layers


layerfor =[]

for i in [10..20]
	layers = genlistLayer(100,120*i,10)
	layerfor[i] = layers

# layerfor[1][2].backgroundColor = "red"
# for k in [0..9]
# 	layerfor[2].backgroundColor ="green"

print layerfor[0]

 

#{}이용하여 Parameter을 사용하기

# #{}으로 이용하여 Parameter이 입력되는 것을 표시할 때 사용
fill = (container, liquid = "coffee") ->
  print "Filling the #{container} with #{liquid}..."
  
fill()

 

For & Object 조합

yearsOld = max: 10, ida: 9, tim: 11

ages = for child, age of yearsOld
  "#{child} is #{age}"

 

 

Object

Object 생성 방법은 중괄호 {} 사용, 개별적인 정보 담는 그릇

객체 리터럴 방식 : 객체 내부에서는 쉼표(,)를 이용해 여러 속성을 지정(세미콘(;) 피할것)

생성자 함수와 new 키워드

var obj = new object();

함수 내부에서는 아래와 같은 일이 발생함.

  1.  함수의 실행 공간(중괄호 내부)에서의 임의의 객체 obj를 생성한다.
  2. obj의 [[proto]]속성에 생성자 함수의 prototype 속성 값을 넣는다.
  3. this라는 키워드에 obj를 대입한다.
  4. this를 반환한다.

여기서 사용하는 this는 new라는 키워드를 사용하지 않을때의 this와 다르다.

 

Property와 value로 구성

Property : 항목이며 string 데이타 타입을 사용해야 함.

Array 집합 [], Array와 Object의 결합 -> [{ }]

Function과 Object가 결합되면 function의 용어가 Method로 달라짐.

 

song = ["do", "re", "mi", "fa", "so"]

singers = {Jagger: "Rock", Elvis: "Roll"}

bitlist = [
  1, 0, 1
  0, 0, 1
  1, 1, 0
]

kids =
  brother:
    name: "Max"
    age:  11
  sister:
    name: "Ida"
    age:  9
    
outer = 1
changeNumbers = ->
  outer = 10
  inner = -1
  #리턴이 생략되어 있어 마지막줄이 return됨
inner = changeNumbers()
print inner
fruit = ["사과", "바나나", "오렌지"]

print fruit

apple = {
	color: "red"
	taste: "great"
	count : "1"
}

print apple.color

#함수명              = Parameter      
color_change_maker= (hi)->
	apple.color = hi
	print apple.color

color_change_maker("Yello")
GreenChange = color_change_maker("Green")

print apple.color	
	
function_set = {
	plus_magic = (a,b) ->
		c = a + b
		print c
		
}

 

 

“Object-Oriented Design Java” OOP의 기본 개념 5가지

  • What are Objects?
  • What are Classes?
  • What is Encapsulation?(캡슐화란 무엇인가?)
  • What is Inheritance?
  • What is Polymorphism?(다형성이란 무언인가?)

 

 

출처 : https://brunch.co.kr/@brunch92ny/8

https://brunch.co.kr/@techhtml/10

https://brunch.co.kr/@hee072794/27

 

11월 10일 진도내용

layerSet = {
	x: 50
	y: 50
	width: 200
	backgroundColor: "red"
}

makeLayer1 = (option) ->
	box = new Layer
#		height: option.height || 500 # nor -> || 
#		width: option.width
#		backgroundColor: option.backgroundColor
	
	for key, value of option # 
		box[key] = value
		print key, value
	
# 	print box.key
# makeLayer1(500, 300, "red")
# makeLayer1(layerSet.height, layerSet.width, layerSet.backgroundColor)
makeLayer1(layerSet)

 

 

makeLayer1 = (option) ->
	box = new Layer
#		height: option.height || 500 # nor -> || 
#		width: option.width
#		backgroundColor: option.backgroundColor
	
	for key, value of option # 
		box[key] = value
	
				
# makeLayer1(500, 300, "red")
# makeLayer1(layerSet.height, layerSet.width, layerSet.backgroundColor)

		
makeLayer1 
	x: 50
	y: 50
	width: 200
	backgroundColor: "red"
	onTap: () ->

# 다음주 진도 내용 Call backfunction

11/23

arrayBox = []
BoxList=[
	{
	key1 : "Trade1"
	value : "$500"
	title :"Wood"
	},
	{
	key1 : "Trade1"
	value : "$500"
	title :"Wood"
	}
	]

makeLayer = (items) ->
	for k in [0...items.length]
		box = new Layer
			x: k*300
	
		textLayer = new Layer
			x: 0
			y: 0
			width: box.width
			height: box.height/3
			html: items[k].value
			parent: box
			
		textLayer = new Layer
			x: 0
			y: 0
			width: box.width
			height: box.height/3
			html: items[k].value
			parent: box
		
makeLayer(BoxList)	

 

According to the NFL, concussions suffered on kickoffs were reduced by 50% due to a 5 yard change in the starting field position on those plays.. It should be noted that Berlichingen, aided by centuries of innovation, was able to do way more with his metal hand than hold a shield. You really should. NFL Jerseys Cheap (a) Representative SBEM single sections (left panels) from SBEM volumes (middle panels) containing a total of 200 slices at 80 nm section thickness in the glial lamina of C57BL and glaucomatous D2 mice show striking differences in the occurrence of evulsions, protrusions and lipid droplets. Division 9: No. The outcome is prompting new calls for the NFL and its regular officials to settle this labor dispute that prompted the league to lock out their officials in June. Because she wholesale football jerseys was a dark skinned Native American Cheyenne and Hodulgee Cheap Jerseys Muscogee Fake Oakleys she was being identified by just her coloring. Eagles center Jason Kelce is going to be completely wholesale jerseys over matched again and Stefen Wisniewski is oakley outlet starting in place of injured Allan Barbre. Salesforce took things a step further on Wednesday. The Sox won it all in 2005, and it was their first title in decades. Scale bar=50m. (A couple important background notes: homosexuality is illegal in Botswana, and I myself am gay.)”. If I want to take you out in 30 seconds, I’ll do that. Don’t worry. Measure the height of the deck in inches. The reason MRE heaters work is because of a chemical reaction between the solid (food grade iron, magnesium, and salt), and water. So, bop, bop, bop; bop, bop, bop. If we saw a bunch of cheerleaders in high school that turned us on, nobody would’ve said jack st about it. It’s like a hundred degrees you can’t run the air where you’re filming. Lea Goldman explored the business behind these campaigns in a 2011 piece for Marie Claire. Lake Arrowhead / Big Bear Lake: Sun and Snow at Mountain Lakes :: Lake Arrowhead, CAThis three day outing in the rugged and scenic San Bernardino Mountains takes you from city noise and traffic to a pair of sparkling, mile high resort communities. Use popular programs, such as Dreamweaver, to create the site or learn HTML and JavaScript. The main exceptions are the candles of the Hanukkah menorah; they’re lit to commemorate a miracle in which a small container of sacred oil burned for eight nights; and the lighting of the candles in the kinara during Kwanzaa each candle symbolizes a different community principle of Kwanzaa.A. These are the 4 pillars of religion. So step forward, feet together, and then step back. Arginine can also prevent episodes of chest pain, or angina, related to coronary artery disease.Arginine may help to ease the symptoms associated with chronic forms of heart failure, including congestive heart failure, according to MedlinePlus. cheap nfl jerseys

답글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다.