我画了下面的图片,演示了如何继承对象(函数构造函数标记为蓝色,从这些构造函数创建的对象标记为绿色):
以下是创建此类层次结构的代码:
function Figure() {}
function Rect() {}
Rect.prototype = new Figure();
function Square() {}
Square.prototype = new Rect();
function Ellipse() {}
Ellipse.prototype = new Figure();
function Circle() {}
Circle.prototype = new Ellipse();
Run Code Online (Sandbox Code Playgroud)
现在我想检查是否new Square()继承自Rect,所以这是我期望JavaScript引擎检查它:
var s = new Square();
s instanceof Rect // ?
s.__proto__ === Rect.prototype // false
new Rect() new Figure()
s.__proto__.__proto__ === Rect.prototype // true
new Figure() new Figure()
Run Code Online (Sandbox Code Playgroud)
所以s instanceof Rect应该回来true.这是预期的,实际上是我运行代码时返回的内容.但后来我想检查是否new Circle()继承自Rect,所以我遵循相同的逻辑:
var …Run Code Online (Sandbox Code Playgroud) 似乎我可以使用registerOnChange或valueChanges方法监听控件的更改.我很困惑何时使用什么.valueChanges返回可观察的,因此使用它是有意义的,因为它提供了许多方便的方法.什么时候用registerOnChange呢?
我试图递归调用以下函数.
public getData(key,value){
this.htmlString += '<span style="color:cornflowerblue">'+key+' </span>:';
if(value instanceof Object){
Object.keys(value).forEach(function (keydata) {
let obj = value[keydata];
this.getData(keydata,value[keydata]);
console.log(key,obj,obj instanceof Object)
});
}else{
this.htmlString += '<span>'+value+'</span>';
}
return this.htmlString;
};
Run Code Online (Sandbox Code Playgroud)
当我试图调用teh函数时它显示错误"无法读取未定义的属性'getData'.代码中是否有任何错误或任何其他方式来执行此操作.
我创建了一个裸存储库,而不是克隆它.当我什么git branch -a都不做的时候表现出来 为什么我甚至没有看到默认master分支?虽然git bash显示如下:
/some/path/project (master)
Run Code Online (Sandbox Code Playgroud) 如何配置PhpStorm在触发格式化时将括号放在同一行(Ctrl + Alt + L)?它目前以这种方式格式化:
function()
{
}
Run Code Online (Sandbox Code Playgroud)
我希望它像这样格式化
function() {
}
Run Code Online (Sandbox Code Playgroud) 是否可以在phpStorm的控制台中运行git命令?例如,我想git log 在我打开的控制台中运行命令Tools->Terminal?
我正在使用带有AngularJS指令的bootstrap UI,我想更改默认样式bootstrap适用于其元素.
我应该从模板中定位HTML内容吗?
基于文档中给出的示例,我想使用手风琴.
当我在HTML中定义它时,它具有以下结构:
<accordion>
<accordion-group heading="my heading">
content here
</accordion-group>
Run Code Online (Sandbox Code Playgroud)
但是当指令处理模板时,它会将其转换为以下HTML:
<accordion close-others="oneAtATime"><div class="panel-group" ng-transclude="">
<div class="panel panel-default ng-isolate-scope" heading="my heading">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" ng-click="toggleOpen()" accordion-transclude="heading">
<span ng-class="{'text-muted': isDisabled}" class="ng-binding">content here</span>
</a>
</h4>
</div>
<div class="panel-collapse collapse" collapse="!isOpen" style="height: 0px;">
<div class="panel-body" ng-transclude=""><span class="ng-scope">some content here</span></div>
</div>
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,它会非常显着地改变它.如果我想更改面板标题的显示方式,我应该在我的css文件中写这个吗?
div.panel {}
Run Code Online (Sandbox Code Playgroud)
并希望模板将来不会改变?
更改指令模板生成的HTML元素样式的最佳方法是什么?
如何全局访问根Angular 2注入器的实例(例如,从浏览器控制台).
在Angular 1中它是angular.element(document).injector().
它在测试和探索过程中非常有用,可以使用浏览器控制台获取注入器,然后访问不同组件,指令,服务等的实例.
我在angular2项目中使用自定义界面并键入别名。例如,我正在实现一个显示产品列表的组件,因此我需要定义 Product接口:
export interface Product {
id: number;
name: string;
price: number;
}
Run Code Online (Sandbox Code Playgroud)
现在我需要一个放置接口的地方。我认为它应该在components文件夹中。我也偷看了源代码,Angular似乎将所有接口都放到了facade文件夹中。因此,我最终得到以下结构:
components
|
|--- product-list
|
|--- facade
| |
| |--- product.ts
|
|--- product-list.component.ts
|--- product-list.component.html
|--- product-list.component.css
Run Code Online (Sandbox Code Playgroud)
该接口的用法如下:
export class RowComponent implements OnInit {
@Input() product: Product;
@Output() productRemoved: EventEmitter<ProductRemoved> = new EventEmitter();
constructor() {
}
Run Code Online (Sandbox Code Playgroud)
这是可行的方法吗?是否有特定于该问题的样式指南?
我有下面的代码,并noImplicitAny:true在tsconfig:
let o = {a: 3};
// works fine
o['a'] = 3;
// reports an error
// Error:(4, 1) TS7017:Index signature of object type implicitly has an 'any' type.
o['b'] = 3;
Run Code Online (Sandbox Code Playgroud)
这个错误是什么意思?
这是在TypeScript游乐场 - 确保单击选项并设置noImplicitAny(似乎不记得可共享链接中的选项).
angular ×4
javascript ×2
phpstorm ×2
typescript ×2
angularjs ×1
css ×1
git ×1
inheritance ×1
recursion ×1