= =是判别左右相等为真
!= 是判别左右不相等为真
function changeStyle() {
var p = document.getElementById("pAugust");
p.style.fontSize = "3rem";
p.style.color = "red";
}
function 1.先宣告 2.再使用
(1)直接写
function func4(n) {
// return "flower";
return n * n;
}
var temp = func4(5); //使用
console.log(temp);
(2)宣告 var = function ()
var demo = function () {
console.log("ok");
};
demo(); //使用
(3)var func5 = function (something)
var func5 = function (something) {
console.log(something);
}
func5("yoyo"); //使用
(4)建立物件 大写、this
function Student(sname, sage) { //S O
this.StudentName = sname; //this S
this.StudentAge = sage; //this S
this.cat = function () {
console.log("喵");
console.log(this.StudentName); //物件里面的属性 this
};
}
var s2 = new Student("No2", 90); //new O
console.log(s2.StudentName); // cat
s2.cat(); //"喵"
console.log("\n\n");
function mysetInterval(a, b) {
a[0] = "apple"; // 5000
console.log(a);
console.log(b);
}
mysetInterval(5000, 1000); //5000 ,1000
正常
var b = function () {
return "bunny";
};
var temp = b();
console.log(temp); // bunny
精简:function拿掉 => 箭头函式
var b = () => {
return "bunny-2";
};
var temp = b();
console.log(temp); // bunny-2
更精简 如果「只做return」,{} 和 return 都可以省略
var b = () => "bunny-3";
//{} return 拿掉
var temp = b();
console.log(temp); // bunny-3
但如果需要多个陈述句子,还是需要加上 () => {}
var c = () => {
var x = 5 + 8; //多的陈述
return x;
};
var temp = c();
console.log(temp); // 13
console.log(this); // window 物件
console.log(window === this); //true
(1)如果单纯使用this(非制作物件),会到另一个世界去(window)
此时程序只能用特定方式使用,不适用正常code
var s1 = {
html: 100,
css: 90,
getTotal: function () {
//不能改成=>函式,this 已经是另一个世界(window)不适用正常code
return this.html + this.css; //this 没有this会变成抓变数
},
};
var temp = s1.getTotal();
console.log(temp); // 190
(2)制作物件(同前function)
function Student(sname, sage) { //S O
this.StudentName = sname; //this S
this.StudentAge = sage; //this S
this.cat = function () {
console.log("喵");
console.log(this.StudentName); //物件里面的属性 this
};
}
var s2 = new Student("No2", 90); //new O
console.log(s2.StudentName); // cat
s2.cat(); //"喵"
console.log("\n\n");
<<: [PoEAA] Data Source Architectural Pattern - Active Record
>>: 微服务、容器化和无服务器(Microservices, Containerization, and Serverless)
第二十七天来讲到第六题练习题 这题题目有点冗长,害得我当时都有点懒得看了 题目大意是:要写一个程序自...
接下来就从两大主题丰收款消费支付API与Shioaji证券API之间,挑一个来进行,既然证券开盘时间...
JDK、JRE 和 JVM 是 Java 编程语言的核心概念!在编程中不使用这些概念,但是作为 Ja...
从昨天的文章中,我们能知道长尾问题在分析用户体验是十分重要的。 在今天,我们将会从现正运行的Act...
通过 JavaScript,咱们能够定义并创建自己的物件,创建新物件有两种不同的方法: 1.使用 O...