I'm new to JavaScript. Just a question on using the spread operator on a class function. An example:
let personA = {
name: "Tom",
testFunction: function() {
// ...
}
};
let newArray = [];
newArray.push({ ...personA });
console.log(newArray);
Run Code Online (Sandbox Code Playgroud)
And the output is:
Run Code Online (Sandbox Code Playgroud)[{ name: 'Tom', testFunction: F}]
But if I use a class, such as:
[{ name: 'Tom', testFunction: F}]
Run Code Online (Sandbox Code Playgroud)
The output is:
Run Code Online (Sandbox Code Playgroud)[{ name: 'Tom'}]
So the function is missing. Isn't everything in JS an object? So why …
我对ASP.NET MVC中的DI有基本的了解,但是有一个问题困扰我很多,将Dbcontext注册为“作用域”或“瞬态”有什么区别吗?以下是典型的mvc应用程序的一些代码:
public class EmployeeController : Controller
{
private EmployeeContext _context;
public EmployeeController(EmployeeContext context)
{
_context = context;
}
public ActionResult Index()
{
return View(context.Employees.ToList());
}
...//other action methods that access context's DbSet
}
Run Code Online (Sandbox Code Playgroud)
假设我们注册EmployeeContext
为临时服务。因此,在我们运行该应用程序之后,该应用程序将监听所有传入的请求。假设发生了一个默认的/ Home / Index的http请求,因此EmployeeController
需要创建一个新的实例,因此DI将首先提供一个实例EmployeeContext
给控制器的构造函数。_context
也可用于所有其他操作方法,并且无需在其他任何地方创建新EmployeeContext
服务。
因此,在请求完成后,_context
也会被处理。那么这与范围服务的效果不一样吗?我们打算将其注册为“瞬态”服务,最后它就像“范围”服务一样工作,因此将Dbcontext注册为“范围”或“瞬态”真的不重要吗?
在index.cshtml中,我使用锚标记助手作为
<a asp-action="Edit" asp-route-id="@Model.Id" asp-route-firstname="@Model.Name"</a>
Run Code Online (Sandbox Code Playgroud)
并在动作方法中
public IActionResult Edit(string id, string firstname)
{
// id and firstname are assigned correct values
// but RouteData.Values only has three entries which are: controller, action and id, where is firstname?
}
Run Code Online (Sandbox Code Playgroud)
但是我不能通过访问访问firstname值,RouteData.Values["firstname"];
而可以通过访问id值RouteData.Values["id"];
,为什么它对id有效但对其他自定义属性无效?