CallConstructor calls the constructor with the given arguments. SCHEME C: For class instances, use this method to create instances. The class constructor function will receive a pre-created instance and initialize it. Instance properties declared in ClassBuilder.Property() are automatically bound to
(args ...*Value)
| 452 | // This replaces the previous NewInstance method and provides automatic property binding |
| 453 | // and simplified constructor semantics where constructors work with pre-created instances. |
| 454 | func (v *Value) CallConstructor(args ...*Value) *Value { |
| 455 | if !v.isAlive() { |
| 456 | return nil |
| 457 | } |
| 458 | cargs := []C.JSValue{} |
| 459 | for _, x := range args { |
| 460 | if !x.belongsTo(v.ctx) { |
| 461 | return nil |
| 462 | } |
| 463 | cargs = append(cargs, x.ref) |
| 464 | } |
| 465 | var val *Value |
| 466 | if len(cargs) == 0 { |
| 467 | val = &Value{ctx: v.ctx, ref: C.JS_CallConstructor(v.ctx.ref, v.ref, C.int(0), nil)} |
| 468 | } else { |
| 469 | val = &Value{ctx: v.ctx, ref: C.JS_CallConstructor(v.ctx.ref, v.ref, C.int(len(cargs)), &cargs[0])} |
| 470 | } |
| 471 | |
| 472 | return val |
| 473 | } |
| 474 | |
| 475 | // Deprecated: Use ToError() instead. |
| 476 | func (v *Value) Error() error { |