연구 설문조사: Blockly 사용 경험을 알려주세요
설문조사 시작
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
차단 > CodeGenerator > provideFunction_
CodeGenerator.provideFunction_() 메서드
생성된 코드에 포함할 개발자 정의 함수 (사용자 정의 프로시져 아님)를 정의합니다. 비공개 도우미 함수를 만드는 데 사용됩니다. 지정된 원하는 이름으로 처음 호출되면 코드가 저장되고 실제 이름이 생성됩니다. 이후의 호출은 동일한 이름을 갖는 것은 아무런 효과가 없지만, 동일한 반환 값을 가집니다.
서로 다른 도우미 함수에 동일한 원하는 이름이 사용되지 않는지 확인하는 것은 호출자에 달려 있습니다 (예: 'random'이 아닌 'colourRandom' 및 'listRandom'을 사용). 예약어, 사용자 정의 변수 또는 프러시저 이름과 충돌할 위험이 없습니다.
CodeGenerator.finish()가 호출되면 코드가 출력됩니다.
서명:
provideFunction_(desiredName: string, code: string[] | string): string;
매개변수
매개변수 |
유형 |
설명 |
desiredName |
문자열 |
원하는 함수 이름입니다 (예: mathIsPrime). |
코드 |
문자열[] | 문자열 |
문 목록 또는 여러 줄의 코드 문자열입니다. ' . (대체됩니다.) |
반환:
문자열
새 함수의 실제 이름입니다. 사용자가 이미 이 이름을 사용하고 있는 경우 원하는 이름과 다를 수 있습니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2024-08-21(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2024-08-21(UTC)"],[[["`CodeGenerator.provideFunction_()` defines developer-defined helper functions for inclusion in the generated code, assigning a unique name to avoid conflicts."],["Calling this method multiple times with the same `desiredName` has no effect but returns the previously assigned unique name."],["Generated helper function code is output when `CodeGenerator.finish()` is called."],["The method takes the desired function name and code as input, returning the actual assigned function name."],["Ensure distinct `desiredName` values for different helper functions to prevent unintended behavior."]]],["The `provideFunction_()` method defines developer-created helper functions for generated code. It takes a `desiredName` and `code` (string or string array). The first call with a `desiredName` saves the `code` and generates a function name. Subsequent calls with the same `desiredName` are ignored. The function name is returned, and may differ from `desiredName` if a name conflict is detected. The code is output when `CodeGenerator.finish()` is called. The method is used to prevent name collisions with user-defined items.\n"]]