2017-12-01 16 views
-2

학교용 JavaScript 연습을하고 있으며 숫자 8은 정말 저를 곤두박질니다.JavaScript 운동 도움말 설정 및 속성 가져 오기

/* 
* @function {Object} Person 
* @param  string name 
*/ 
function Person(name) { 
    // Todo: Complete the function 

} 


var Mike = Person('John Doe'); 
var Bob = Person('John Doe'); 
var Worker = Person('John Doe'); 

/* 
* Directions Part 1: 
* - Update the Person function so the below statements don't generate any errors 
*/ 
Mike.setName('Mike'); // name setter 
Mike.getName();   // name getter 


/* 
* Directions Part 2: 
* - Update the Person function so the below statements don't generate any errors 
*/ 
Bob.name('Bob'); // name setter 
Bob.name();   // name getter 


/* 
* Directions part 3: 
* - Update the Person function so the below statements don't generate any errors 
* 
*/ 
Worker.setName('Kevin');   // name setter 
Worker.profession('Programmer'); // profession setter 
Worker.profession();    // profession getter 

Worker.introduce();     // Calling this method, the Person will introduce themselves with their name and profession. 

내 혼란의 일부는 내가 확실히 그것이 나에게 요구 무슨 이해하지 못하는 것을 생각 : 여기

은 원래의 완전한 운동이다. 다른 부분은이 코딩 스타일이 나에게 익숙하지 않다는 것입니다. 보통 이런 식의 유동적 인 문장이 없기 때문입니다.

최종 결과는 이름과 직업을 제공하는 것이어야하지만이 방법이 제공되는 경로를 볼 수는 없습니다.

+0

'도도는 다음 function'를 완료 ... 음 ... 당신이? 우리가 당신을 위해 숙제를 할 것으로 기대하지 마십시오 : p –

+0

아니요, 어떻게해야할지 모르겠습니다. – Jeremy

+1

[숙제 질문 및 답변 방법] (https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions/334823?s=3|0.0000) # 334823) – charlietfl

답변

0

은 다음과 같이이다 :

//<![CDATA[ 
 
/* external.js */ 
 
var doc, bod, I, Person, old = onload; // for use on other loads 
 
onload = function(){ 
 
if(old)old(); // change old var name if using technique on other pages 
 
doc = document; bod = doc.body; 
 
I = function(id){ 
 
    return doc.getElementById(id); 
 
} 
 
Person = function(last, first, middle, job){ 
 
    this.first = first; this.middle = middle; this.last = last; this.job = job; 
 
    this.firstName = function(first){ 
 
    if(first === undefined){ 
 
     return this.first; 
 
    } 
 
    this.first = first; 
 
    return this; 
 
    } 
 
    this.middleName = function(middle){ 
 
    if(middle === undefined){ 
 
     return this.middle; 
 
    } 
 
    this.middle = middle; 
 
    return this; 
 
    } 
 
    this.lastName = function(last){ 
 
    if(last === undefined){ 
 
     return this.last; 
 
    } 
 
    this.last = last; 
 
    return this; 
 
    } 
 
    this.profession = function(profession){ 
 
    if(profession === undefined){ 
 
     return this.job; 
 
    } 
 
    this.job = profession; 
 
    return this; 
 
    } 
 
} 
 
var out = I('out'), newbie = new Person; 
 
newbie.firstName('Bob').lastName('Smith').profession('plummer'); 
 
out.innerHTML = newbie.lastName()+', '+newbie.firstName()+'; profession:'+newbie.profession(); 
 
/* you wouldn't need to use empty methods, with this design though 
 
out.innerHTML = newbie.last+', '+newbie.first+'; profession:'+newbie.job; 
 
would also work 
 
*/ 
 

 
} 
 
//]]>
/* external.css */ 
 
html,body{ 
 
    padding:0; margin:0; 
 
} 
 
body{ 
 
    background:#000; overflow-y:scroll; 
 
} 
 
.main{ 
 
    width:936px; background:#ccc; padding:20px; margin:0 auto; 
 
} 
 
#out{ 
 
    background:#fff; padding:10px; 
 
}
<!DOCTYPE html> 
 
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'> 
 
    <head> 
 
    <meta http-equiv='content-type' content='text/html;charset=utf-8' /> 
 
    <meta name='viewport' content='width=device-width' /> 
 
    <title>test</title> 
 
    <link type='text/css' rel='stylesheet' href='external.css' /> 
 
    <script type='text/javascript' src='external.js'></script> 
 
    </head> 
 
<body> 
 
    <div class='main'> 
 
    <div id='out'></div> 
 
    </div> 
 
</body> 
 
</html>