我正在阅读JavaScript教程,我可以完成它.但问题是我不明白其中一条线在做什么.我有一个函数setAge(),然后在创建一个susan对象后,我将该对象的一个属性设置为函数的名称?我不明白为什么这样做.如果不这样做,我不能使用函数/方法吗?
教程代码:
var setAge = function (newAge) {
this.age = newAge;
};
var susan = new Object();
susan.age = 25;
susan.setAge = setAge; //how the hell does this work?
// here, update Susan's age to 35 using the method
susan.setAge(35);
Run Code Online (Sandbox Code Playgroud) 这是一个新的任务.我想要的答案/输出是正确的.我只是不明白为什么.如果电源功能与我检查的数字相匹配,我希望输出为真.我确实得到了这些例子的答案,但我不明白这个递归函数是如何工作的.
在这个函数的else中,我说base*函数本身.甚至代表什么?怎么可以base * power(base, exponent - 1);计算?它不应该只是围成一圈然后最终结束?
console.log(power(2,4) === 16);
console.log(power(2,3) === 8);
console.log(power(2,2) === 4);
var power = function(base, exponent) {
if(exponent === 0) {
return 1;
}
else {
return base * power(base, exponent - 1);
}
};
Run Code Online (Sandbox Code Playgroud) 我正在尝试在我制作的新课程中制作一个方法......
public void CalcDrinks(bool HealthOption)
{
if (HealthOption)
{
CostOfBeverage = 5M;
}
else
{
CostOfBeverage = 20M;
}
}
Run Code Online (Sandbox Code Playgroud)
我一直在虚空之下得到一个红色的波浪形......"预期的类,代表,枚举,接口或结构错误"
我不确定我错过了什么......
我不确定这里发生了什么,我创建了一个非常基本的HTML/CSS页面,它只是在浏览器中显示一个空白页面.
<HTML>
<head>
<style type="text/css">
#sidebar {float:left; width:20%;}
.post {float:right; width:79%;}
#footer {clear:both;}
</head>
<body>
<div id="header">
<h1>My interesting life</h1>
</div>
<div id="sidebar">
<h2>Menu</h2>
<ul>
<li>Place Link Here</li>
<li>Place Link2 Here</li>
</ul>
</div>
<div class="post">
<h2>Yesterday</h2>
<p>Today I drank coffee for breakfast. 14 hours later, I went to bed. </p>
</div>
<div class="post">
<h2>Yesterday</h2>
<p>Ran out of coffee, so had orange juice for breakfast. It was from concentrate.</p>
</div>
<div id="footer">
<p><small> This is copyright by Monu. Contact me to …Run Code Online (Sandbox Code Playgroud) 老实说......我不知道我做错了什么......我得到了错误
你调用的对象是空的
代码如下所示,我使用了标记错误/////.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MonuEventPlanning
{
public partial class Form1 : Form
{
DinnerFun dinnerFun;
public Form1()
{
InitializeComponent();
DinnerFun dinnerFun = new DinnerFun { PeepQty = (int)nudPeepQty.Value };
}
public void btnCalc_Click(object sender, EventArgs e)
{
dinnerFun.CalcDrinks(cbxHealthy.Checked); ///////PROBLEM HERE////////////////
dinnerFun.CalcDecorations(cbxFancy.Checked);
DisplayCost();
}
public void DisplayCost()
{
tbxDisplayCost.Text = dinnerFun.CalcTotalCost(cbxHealthy.Checked).ToString("c");
}
}
Run Code Online (Sandbox Code Playgroud)
}
这是我正在做的这个练习项目的另一页代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data; …Run Code Online (Sandbox Code Playgroud)