Blogger Information
Blog 12
fans 1
comment 0
visits 9863
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS对象、封装、构造函数0710
简简单单的博客
Original
950 people have browsed it

创建全局变量、创建全局函数

var mingchen = '净水';

function good(value){

var site = '好用';

return value + site;

}

console.log( good(mingchen) );

输出净水好用

for循环的运用,continue,是介绍当前循环,进入下一个循环。

实例

<script>
for (var i =0;i < 10;i++){
if(i===4)continue;
document.write(i+'</br>');
}
</script>

运行实例 »

点击 "运行实例" 按钮查看在线实例

构造函数

实例

<script>
var CreateObj = function() {
this.domain = 'php.cn';
this.get = function (value) {
var site = 'php中文网:';
return site + value;
};
};
var obj1 = new CreateObj();
console.log(obj1.domain);
console.log(obj1.get(obj1.domain));
</script>

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

CreateObj.email = 'admin@php.cn';
CreateObj.hello = function () {
    return 'hello js真的好难呀';
};
console.log(CreateObj.email);
console.log(CreateObj.hello());

运行实例 »

点击 "运行实例" 按钮查看在线实例

因为函数也是对象,是对象就可以拥有属性和方法,

直接添加到构造函数上,不需要通过实例访问,直接用构造函数对象访问就可以了



Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post