CodeSampleX

샘플

function-bind 1.1.2: bind a function to a context with partial arguments using function-bind

검증된 샘플 — npm function-bind 1.1.2: bind a function to a context with partial arguments using function-bind. node 22 · linux alpine/x64 · docker에서 contract를…

sha256:bd8e8235756ac8a10da9988c9736be28ff6032e6a597ed0987566ebc912a6be0

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 windows 11 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-19

케이스

HOW
목표
bind a function to a context with partial arguments using function-bind
패키지
심벌
  • function-bind
생성일
2026-08-18T18:02:20Z

컨트랙트

  1. bind binds context and prepends arguments to function calls
  2. bind correctly calculates the length of the bound function
  3. bind creates a constructor that instantiates the target when called with new
  4. bind throws a TypeError when called on a non-function target

파일

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: bind a function to a context with partial arguments using function-bind
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/function-bind@1.1.2
Demonstrate these symbols/APIs:
  - function-bind
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@11.8.0
  - runtime: node@24.13.1

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:80b6ca41baa2684659d09f13e783f8c3dd8e1e4185eb011721dcc8d919609102","constraints":{"executionContext":"node"},"contract":["bind binds context and prepends arguments to function calls","bind correctly calculates the length of the bound function","bind creates a constructor that instantiates the target when called with new","bind throws a TypeError when called on a non-function target"],"goal":"bind a function to a context with partial arguments using function-bind","kind":"HOW","packages":["pkg:npm/function-bind@1.1.2"],"schemaVersion":1,"symbols":["function-bind"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","os":"windows","osVersionBucket":"11","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/function-bind@1.1.2"],"schemaVersion":1,"symbols":["function-bind"],"verifierAdapter":"node-typescript@1"}
index.mjs
import bind from 'function-bind';

/**
 * Binds a function to a context object with optional prepended arguments.
 * @param {Function} fn - The target function to bind.
 * @param {*} thisArg - The value to be passed as the this parameter to the target function.
 * @param {...*} args - Arguments to prepend to arguments provided to the bound function.
 * @returns {Function} A copy of the given function with the specified this value and initial arguments.
 */
export function bindFunction(fn, thisArg, ...args) {
  return bind.call(fn, thisArg, ...args);
}

export default bind;
package-lock.json
{
  "name": "sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample",
      "version": "1.0.0",
      "dependencies": {
        "function-bind": "1.1.2"
      }
    },
    "node_modules/function-bind": {
      "version": "1.1.2",
      "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
      "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
      "license": "MIT",
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "function-bind": "1.1.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "bind a function to a context with partial arguments using function-bind",
  "kind": "HOW",
  "packages": [
    "pkg:npm/function-bind@1.1.2"
  ],
  "symbols": [
    "function-bind"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@11.8.0",
    "runtime": "node@24.13.1"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import bind from 'function-bind';

assert.equal(typeof bind, 'function', 'function-bind must be a function');

// Contract 1: bind binds context and prepends arguments to function calls
{
  function greet(greeting, punctuation) {
    return `${greeting}, ${this.name}${punctuation}`;
  }

  const context = { name: 'World' };
  const sayHello = bind.call(greet, context, 'Hello');

  assert.equal(sayHello('!'), 'Hello, World!');
  assert.equal(sayHello('?'), 'Hello, World?');

  function add(a, b, c) {
    return (this ? this.base : 0) + a + b + c;
  }
  const boundAdd = bind.call(add, { base: 10 }, 1, 2);
  assert.equal(boundAdd(3), 16);
}

// Contract 2: bind correctly calculates the length of the bound function
{
  function sum4(a, b, c, d) {
    return a + b + c + d;
  }

  const bound0 = bind.call(sum4, null);
  assert.equal(bound0.length, 4);

  const bound1 = bind.call(sum4, null, 1);
  assert.equal(bound1.length, 3);

  const bound3 = bind.call(sum4, null, 1, 2, 3);
  assert.equal(bound3.length, 1);

  const bound4 = bind.call(sum4, null, 1, 2, 3, 4);
  assert.equal(bound4.length, 0);

  const bound5 = bind.call(sum4, null, 1, 2, 3, 4, 5);
  assert.equal(bound5.length, 0);
}

// Contract 3: bind creates a constructor that instantiates the target when called with new
{
  function Point(x, y) {
    this.x = x;
    this.y = y;
  }

  Point.prototype.getDistance = function () {
    return Math.sqrt(this.x * this.x + this.y * this.y);
  };

  const YPoint = bind.call(Point, null, 0);
  const p = new YPoint(5);

  assert.equal(p instanceof Point, true);
  assert.equal(p.x, 0);
  assert.equal(p.y, 5);
  assert.equal(p.getDistance(), 5);
}

// Contract 4: bind throws a TypeError when called on a non-function target
{
  assert.throws(
    () => bind.call(null, {}),
    TypeError
  );

  assert.throws(
    () => bind.call(123, {}),
    TypeError
  );

  assert.throws(
    () => bind.call('string', {}),
    TypeError
  );
}

console.log('All contract assertions passed successfully.');

오리진 시더

익명