연구 설문조사: Blockly 사용 경험을 알려주세요
설문조사 시작
명세서
문 블록은 출력 연결이 없는 블록입니다. 이들은 다음과 같이 작동합니다.
문장을 텍스트 기반 언어로 작성할 수 있습니다.
Blockly의 모든 블록과 마찬가지로 문 블록을 코드로 변환할 수 있습니다.
문자열을 생성할 수 있습니다.
import {javascriptGenerator} from 'blockly/javascript';
javascriptGenerator.forBlock['custom_block'] = function(block, generator) {
// Collect argument strings.
const fieldValue = block.getFieldValue('MY_FIELD');
const innerCode = generator.statementToCode(block, 'MY_STATEMENT_INPUT');
// Return code.
return 'my code string';
}
인수 문자열 수집
모든 블록 코드 생성기에는
필드 값 수집 및 필드의 코드 수집은
내부 블록과 동일합니다.
// Collect field values.
const fieldValue = block.getFieldValue('MY_FIELD');
// Collect inner block code strings.
const innerCode = generator.statementToCode(block, 'MY_STATEMENT_INPUT');
내부 블록의 코드를 여러 번 참조하는 경우
인수 캐싱을 지원합니다.
반환 값
문 블록 코드 생성기의 반환 유형은 코드 문자열입니다.
return 'my code string';
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2024-10-15(UTC)
[null,null,["최종 업데이트: 2024-10-15(UTC)"],[[["Statement blocks in Blockly, similar to statements in text-based languages, lack output connections and function by defining a block-code generator to convert them into code strings."],["Generating code for statement blocks involves collecting values from fields and inner blocks using dedicated functions within the block-code generator."],["Block-code generators for statement blocks return code strings, representing the translated code for the block, and optionally incorporate argument caching for optimized code generation."]]],["Statement blocks, which lack output connections, are converted to code strings using block-code generators. This process involves collecting values from fields and code from inner blocks. The `getFieldValue` method retrieves field values, while `statementToCode` gathers inner block code. If inner block code is used multiple times, argument caching is recommended. Ultimately, a statement block-code generator returns a string representing the generated code.\n"]]