我的问题是context.beginPath()和context.closePath().下面的代码将在屏幕周围绘制一个圆弧,直到它消失,然后是一个小点,我会注释掉,因为它是一个我不知道如何包含的.jpg.
我的问题是beginPath()究竟做了什么以及closePath()做了什么?
如果我评论它们,除了我期待的结果之外,我得到了一个疯狂的结果.我看过互联网,但我还没有看到这样的结果.
代码有问题:
function drawTheBall() {
context.fillStyle = "#00AB0F"; //sets the color of the ball
context.beginPath();
context.arc(ball.x,ball.y,10,0,Math.PI*2,true); //draws the ball
context.closePath();
context.fill();
}
Run Code Online (Sandbox Code Playgroud)
下面的工作代码
HTML,Java脚本
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CH5EX10: Moving In Simple Geometric Spiral </title>
<script src="modernizr.js"></script>
<script type="text/javascript">
window.addEventListener('load', eventWindowLoaded, false);
function eventWindowLoaded() {
canvasApp();
}
function canvasSupport () {
return Modernizr.canvas;
}
function canvasApp() {
var radiusInc = 2;
var circle = {centerX:250, centerY:250, radius:2, angle:0, radiusInc:2}
var ball …Run Code Online (Sandbox Code Playgroud) 此代码有效,但如何实际调用任何列出的方法.它的工作原理,但似乎它几乎是神奇的,为什么它的工作原理.我从来没有实际调用Equals,GetHashCode或Compare,但代码有效.我也从不在构造函数中为实现两个接口的EmployeeComparer类调用任何东西.
问题:当这个类与新的KeyWord实现时,这是否会自动完成?(有些事情似乎不对劲)
public class EmployeeComparer : IEqualityComparer<Employee>,
IComparer<Employee>
Run Code Online (Sandbox Code Playgroud)
public bool Equals(Employee x, Employee y)
{
return String.Equals(x.Name, y.Name);
}
public int GetHashCode(Employee obj)
{
return obj.Name.GetHashCode();
}
public int Compare(Employee x, Employee y)
{
return String.Compare(x.Name, y.Name);
}
Run Code Online (Sandbox Code Playgroud)
类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public delegate void Del(string e);
Del handler = DelegateMethod;
Dictionary<string, List<Employee>> d = new Dictionary<string,
List<Employee>>();
public static void DelegateMethod(string message)
{
System.Console.WriteLine(message);
System.Console.ReadKey();
} …Run Code Online (Sandbox Code Playgroud) 我想创建一个JQuery例程,可以将信息(追加)写入存在或不存在的文本文件中.如果文件不存在而不是它应该创建文件,如果它存在,它应该追加或开始将新数据写入文件.我认为append将是文件记录器的最佳选择.所以它必须将数据附加到文件中.
我在互联网上找到了这个代码,我正在努力解决它,以便我可以在我的页面上使用它来将信息写入一个简单的文本文件.
问题:如何将以下代码记录到文件中以供下载?
下面是新代码以及我如何阅读有关Java脚本中的记录器应如何工作的注释中列出的页面.代码不起作用,我不确定为什么.
我不确定下载是如何工作的,但如果我能让记录器工作,我会很高兴暂时.
码:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
<script src="log4moz.js">
</head>
<script>
getLocalDirectory : function() {
let directoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
// this is a reference to the profile dir (ProfD) now.
let localDir = directoryService.get("ProfD", Ci.nsIFile);
localDir.append("XULSchool");
if (!localDir.exists() || !localDir.isDirectory()) {
// read and write permissions to owner and group, read-only for others.
localDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0774);
}
return localDir;
}
let myFile = XULSchool.getLocalDirectory();
myFile.append("someFile.txt");
let formatter = new Log4Moz.BasicFormatter();
let root = Log4Moz.repository.rootLogger;
let logFile …Run Code Online (Sandbox Code Playgroud) 我正在制作这个培训视频.我在下面的示例中注意到,我的代码每次都会将最后一项留在列表中.在我使代码更加花哨和可读之前,它工作正常.
问题:为什么我的代码会关闭最后一项?
SortedDictionary<string, SortedSet<Employee>>
Run Code Online (Sandbox Code Playgroud)
码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
private void printDictionary(Dictionary<string, List<Employee>> InputDictionaryParm1)
{
foreach (var a in InputDictionaryParm1)
{
Console.WriteLine(a.Key);
foreach (var e in a.Value)
{
Console.WriteLine("\t" + e.Name);
}
}
Console.ReadKey();
}
static void Main(string[] args)
{
var d = new DepartmentCollection();
d.AddDept("AA", new Employee { Name = "L" })
.AddDept("AA", new Employee { Name = "A" });
d.AddDept("BB", new Employee { Name = "D" })
.AddDept("BB", …Run Code Online (Sandbox Code Playgroud) 为什么我不能像现在这样调用我的功能?如果我在main方法中有它,printDictionary的代码就可以正常工作.我想将它移动到一个函数,然后只需使用它传递我的参数,但它会给出底部列出的错误.
问题:当我只想调用函数进行打印时,我错过了什么会导致下面的错误?
printDictionary(d); <-- Error
Run Code Online (Sandbox Code Playgroud)
电话代码:
printDictionary(d);
Run Code Online (Sandbox Code Playgroud)
通话功能:
private void printDictionary(Dictionary<string, List<Employee>>
InputDictionaryParm1)
{
foreach (var a in InputDictionaryParm1)
{
Console.WriteLine(a.Key);
foreach (var e in a.Value)
{
Console.WriteLine("\t" + e.Name);
}
}
Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud)
错误表:
Error 1 The best overloaded method match for 'ConsoleApplication1.Program.printDictionary(System.Collections.Generic.Dictionary<string,System.Collections.Generic.List<ConsoleApplication1.Employee>>)' has some invalid arguments C:\Users\itpr13266\AppData\Local\Temporary Projects\ConsoleApplication1\Program.cs 52 13 ConsoleApplication1
Error 2 Argument 1: cannot convert from 'System.Collections.Generic.SortedDictionary<string,System.Collections.Generic.SortedSet<ConsoleApplication1.Employee>>' to 'System.Collections.Generic.Dictionary<string,System.Collections.Generic.List<ConsoleApplication1.Employee>>' C:\Users\itpr13266\AppData\Local\Temporary Projects\ConsoleApplication1\Program.cs 52 29 ConsoleApplication1
Run Code Online (Sandbox Code Playgroud)