我有 2 个特质和 1 个职业。
在 Trait 中A,方法A1和实现都A2需要实现
scala> trait A {
| def A1
| def A2
| }
defined trait A
Run Code Online (Sandbox Code Playgroud)
在 Trait 中B,尽管A1在这里实现了,但它需要是抽象的,因为它使用了 super 并且仍然需要在实例类中实现。A2已实施
scala> trait B extends A {
| abstract override def A1 = {
| super.A1
| }
| def A2 = println("B")
| }
defined trait B
Run Code Online (Sandbox Code Playgroud)
现在我有一个C定义的类A1(与以前的特征无关)
scala> class C {
| def A1 = …Run Code Online (Sandbox Code Playgroud) I have a grid with 3 rows, 1 column and item of the middle row is a grid itself of 2 columns and 4 rows.
CSS Snippet
.css-grid-container-common-styles{
height:100vh; /*???*/
display: grid;
grid-template-columns: 1fr; /* 1column*/
grid-template-rows: auto 15fr 1fr; /* 3 rows. Auto takes height of navigation, remaininign is divided into 2 rows, middle row is 15 times larger than the 3rd row.*/
}
Run Code Online (Sandbox Code Playgroud)
HTML Snippet
<div class="css-grid-container-common-styles"> <!-- first container -->
<nav class="navbar navbar-expand-lg navbar-light bg-light css-grid-item-nav-div-common-styles"> <!-- …Run Code Online (Sandbox Code Playgroud) 我正在对使用其他两个组件的组件进行单元测试。单击按钮时创建其他组件
.html
<div id="homepage-top-div" class="homepage-component-css-grid-container"> ...
<button id="get-question-list-button" [routerLink]="questionListRouterLink" class="btn content-div__button--blue css-grid-item-button-div btn-sm">See Questions</button>
</div>
<div id="practice-component-top-div" class="css-grid-container-div common-styles-div--white"> <!-- 4 rows, 1 column-->
...
<button id="new-question-button" [routerLink]="newQuestionRouterLink" class="btn content-div__button--blue css-grid-item-button-div btn-sm">Create a Question</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
.ts
export class HomepageContentComponentComponent implements OnInit {
public questionListRouterLink="/practice-question-list";
public newQuestionRouterLink="/new-practice-question";
constructor() {
}
ngOnInit() {
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个,spec但运行时出现以下错误-Failed: Unexpected directive 'NewPracticeQuestionComponent' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation.
规格是
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing'; …Run Code Online (Sandbox Code Playgroud) 我正在Component使用其他两个组件进行单元测试。单击按钮时创建其他组件
.html
<div id="homepage-top-div" class="homepage-component-css-grid-container"> ...
<button id="get-question-list-button" [routerLink]="questionListRouterLink" class="btn content-div__button--blue css-grid-item-button-div btn-sm">See Questions</button>
</div>
<div id="practice-component-top-div" class="css-grid-container-div common-styles-div--white"> <!-- 4 rows, 1 column-->
...
<button id="new-question-button" [routerLink]="newQuestionRouterLink" class="btn content-div__button--blue css-grid-item-button-div btn-sm">Create a Question</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
.ts
export class HomepageContentComponentComponent implements OnInit {
public questionListRouterLink="/practice-question-list";
public newQuestionRouterLink="/new-practice-question";
constructor() {
}
ngOnInit() {
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个规范,但是运行它时出现以下错误- Error: StaticInjectorError[Location]:
NullInjectorError: No provider for Location!
规格是
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
import { HomepageContentComponentComponent } from './homepage-content-component.component';
import …Run Code Online (Sandbox Code Playgroud) 问题1 - 当我将List与Set(不同元素)进行比较时,为什么此代码返回true,但当我将List与List或Set of?进行比较时返回false?
scala> val l = List(1,2,3)
l: List[Int] = List(1, 2, 3)
scala> val l2=List(1,2,3)
l2: List[Int] = List(1, 2, 3)
scala> val l3=List(1,3,3)
l3: List[Int] = List(1, 3, 3)
scala> l.canEqual(l2)
res2: Boolean = true
/*I guess this returns true becuase canEqual check for type of the passed instance. Something like def canEqual(other: Any): Boolean = other.isInstanceOf[List] */
scala> l.canEqual(l3)
res3: Boolean = true
//but if canEqual checks for type of passed instance then why this …Run Code Online (Sandbox Code Playgroud) 在下面的代码中,我可以定义id为List[I]
abstract trait Repository[I,M] {
def getOneById(id: List[I]): Option[M]
}
Run Code Online (Sandbox Code Playgroud)
但是,为什么我不能定义id为List[I]下面的代码?
abstract trait Repository[List[I],M] {
def getOneById(id: List[I]): Option[M] //I get compiler error - cannot resolve I. Why?
}
Run Code Online (Sandbox Code Playgroud) 我想创建toString()以下a对象的自定义方法.但我无法这样做.我读过我应该覆盖prototype.toString但我得到编译错误
var a = {
someProperty: 1,
someotherProperty:3
}
a.prototype.toString = function customPrint(){
return "the custom print is "+(someProperty+someotherProperty);
}
var b = {
somePropertyb: 2
}
function printObject(){
console.log("using , hello: a:",a,"b:",b); //prints using , hello: a: { someProperty: 1, someotherProperty: 3 } b: { somePropertyb: 2 }
console.log("using + hello: a:"+a+"b:"+b);//prints using + hello: a:[object Object]b:[object Object] if I remove a.prototype.toString code
}
printObject()
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
node print.js
print.js:6
a.prototype.toString = function customPrint(){ …
我发现使用match比if. 如果我有一个boolean值,我可以将它与 一起使用match吗?
我通常这样做
if(!authorised) {...} else {..}
Run Code Online (Sandbox Code Playgroud)
但我无法做到
authorised match {
case ??? //what here??
}
Run Code Online (Sandbox Code Playgroud) 我不知道如何写c#代码。我试图在这里运行示例代码 - https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/quickstart-dotnet?tabs=azure-portal%2Cwindows%2Cpasswordless%2Csign-in- azure-cli#创建帐户
这是我复制到的代码powershell。当我这样做时dotnet run,我收到错误
/home/manu/Program.cs(24,1): error CS8803: Top-level statements must precede namespace and type declarations. [/home/manu/manu.csproj]
The build failed. Fix the build errors and run again.
Run Code Online (Sandbox Code Playgroud)
代码
// See https://aka.ms/new-console-template for more information
using Microsoft.Azure.Cosmos;
using Azure.Identity;
// New instance of CosmosClient class
using CosmosClient client = new(
accountEndpoint: Environment.GetEnvironmentVariable("COSMOS_ENDPOINT"),
tokenCredential: new DefaultAzureCredential()
);
// C# record representing an item in the container
public record Product(
string id,
string categoryId,
string categoryName, …Run Code Online (Sandbox Code Playgroud) 我在一本书中找到了以下代码
val list = List(5, 4, 3, 2, 1)
val result = (0 /: list) { (`running total`, `next element`) ?
`running total` - `next element`
}
Run Code Online (Sandbox Code Playgroud)
反引号用于创建带空格的变量名吗?
如果我通过,则以下 JavaScript 函数有效,event但如果我通过,则会出错$event。两者有什么区别,为什么不起作用$event?
function IWasClicked(event) {
alert("clicked again with event",event);
}
Run Code Online (Sandbox Code Playgroud)
这不起作用,并且$event没有定义给HTMLAnchorElement.onclick
function IWasClicked(event) {
alert("clicked again with event",event);
}
Run Code Online (Sandbox Code Playgroud)
这有效
<div id="about"><a class="selected-button" href="javascript:void(0)" onclick="IWasClicked($event)">About</a></div>
Run Code Online (Sandbox Code Playgroud) scala ×5
angular6 ×2
javascript ×2
angular ×1
c# ×1
centering ×1
css ×1
css-grid ×1
flexbox ×1
if-statement ×1