小编Nit*_*esh的帖子

在Javascript toString中获取价值

我有一个非常简单的问题.

在Javascript中,

"你好"+ function(){}

将打印 "hellofunction(){}"

因为Function.prototype将调用自己的toString方法,它将返回"function(){}"

现在,我想重写toString方法:

Function.prototype.toString = function(){
return "my" + SOME_PROPERTY + "output"
}
Run Code Online (Sandbox Code Playgroud)

在这个自定义方法中,我想function(){} 知道如何在toString方法中获取当前值,因为我无法toString再次执行,因为它将进行递归.

我希望最终输出为:

"myfunction(){}output"
Run Code Online (Sandbox Code Playgroud)

javascript prototype object

3
推荐指数
1
解决办法
40
查看次数

在 Angular2+ 中将外部组件作为属性传递

假设有一个组件ButtonComponent 和SideComponent。如何将“ButtonComponent”作为属性传递给“SideComponent”?

例如,

@Component({
  selector: 'my-btn',
  template: '<span>My button</span>'
})
export class ButtonComponent implements OnInit {

} 


@Component({
  selector: 'my-side',
  template: '<div><div class="btn-section">{{myBtn}}</div><div class="content-section"><ng-content></ng-content></div></div>'
})
export class SideComponent implements OnInit {
   @Input() myBtn:any = null;
}

Usage:
<my-side [myBtn]="btnTmpl">
  Hello, this is my content
</my-side>
<my-btn #btnTmpl></my-btn> 
Run Code Online (Sandbox Code Playgroud)

但这不起作用,最终模板显示 [Object Object] 作为输出。

angular angular5 angular6

0
推荐指数
1
解决办法
1640
查看次数

标签 统计

angular ×1

angular5 ×1

angular6 ×1

javascript ×1

object ×1

prototype ×1