<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script language="javascript" type="text/javascript">
function aa() {
window.alert("aa");
}
var bb = function () {
window.alert("bb");
}
var cc = new Function("window.alert('cc');");
window.alert(typeof cc);
</script>
</head>
<body> </body>
</html>

fun01

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script language="javascript" type="text/javascript">
function fn1() {
window.alert("fn1");
} //fn1();
var fn2 = fn1; fn2(); fn1 = function () {
window.alert("new fn1");
}; fn2(); fn1(); </script>
</head>
<body> </body>
</html>

fun02

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script language="javascript" type="text/javascript">
function sum1(a, b) {
return a + b;
}
function sum1(a) {
return a + a;
}
//window.alert(sum1(4, 5));
window.alert(sum1(4,5)); </script>
</head>
<body> </body>
</html>

fun03

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>function 参数</title>
<script language="javascript" type="text/javascript">
function callFun(fun, arg) {
return fun(arg);
} function say(name) {
window.alert(name);
} //say("wyp");
callFun(say, "wyp"); function say(name) {
window.alert("new " + name);
}
callFun(say, "wyp"); var cc = new Function("name", "say(name)");
cc("wangyp"); var ss = [1, 2, 11, 13, 12, 119];
window.alert(ss);
ss.sort(sortBy);
window.alert(ss); function sortBy(a, b) {
return a - b;
}
</script>
</head>
<body> </body>
</html>

fun04

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>function 返回值</title>
<script language="javascript" type="text/javascript">
//function fn1(a) {
// var fnn1 = function (b) {
// return a + b;
// }
// return fnn1;
//}
//var fn11 = fn1(3);
//window.alert(fn11(4)); function compareProp(prop) {
var fn1 = function (obj1, obj2) {
if (obj1[prop] > obj2[prop]) return 1;
else if (obj1[prop] < obj2[prop]) return -1;
return 0;
}
return fn1;
} var person1 = { name: 'wyp', age: 33 };
var person2 = { name: 'zyx', age: 23 };
var person3 = { name: 'hg', age: 27 };
var persons = [person1, person2, person3];
//for (var i = 0 ; i < persons.length; i++) {
// window.alert(persons[i].name + "," + persons[i].age);
//}
var comparePropFun = compareProp("name");
persons.sort(comparePropFun);
for (var i = 0 ; i < persons.length; i++) {
window.alert(persons[i].name + "," + persons[i].age);
}
</script>
</head>
<body> </body>
</html>

fun05

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script language="javascript" type="text/javascript">
//function fn() {
// window.alert(arguments.length);
// var result = 0;
// for (var i = 0 ; i < arguments.length ; i++) {
// result += arguments[i];
// }
// return result;
//} //window.alert(fn(1, 3, 5)); function sum(num) {
if (num == 1) {
return 1;
}
else {
return num * arguments.callee(num - 1);
//return num * sum(num - 1);
}
}
//window.alert(sum(3)); var fn = sum;
sum = null;
window.alert(fn(3)); </script>
</head>
<body> </body>
</html>

fun06

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script language="javascript" type="text/javascript">
function Person(name, age) {
this.name = name;
this.age = age;
}
window.alert(typeof Person);
var person = new Person("wyp",33);
//person.name = "wyp";
window.alert(typeof person);
window.alert(person.name); //function Person(name, age) {
// window.alert(arguments.length);
//} //window.alert(Person.length);
//Person(10);
</script>
</head>
<body> </body>
</html>

fun07

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script language="javascript" type="text/javascript">
var person1 = { name: "wyp", age: 33 };
var person2 = { name: "cr", age: 29 }; function show(a, b) {
window.alert("name=" + this.name + ",a=" + a + ",b=" + b);
}
show(3, 4);
show.apply(person1, [3, 4]);
show.call(person2, 3, 4);
</script>
</head>
<body> </body>
</html>

fun08

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script language="javascript" type="text/javascript">
var person = '{ name: "wyp", age: 32 }';
//var obj = eval("(" + person + ")");
var obj = new Function("return " + person)();
window.alert(obj.name);
</script>
</head>
<body> </body>
</html>

json1

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script language="javascript" type="text/javascript">
//var aa = new Array();
//var aa = new Object();
var aa = { }; aa[0] = "wyp";
aa[1] = "wangyunpeng";
aa.name = "shuaige";
//aa["name"];
//aa.name;
window.alert(aa[1]);
</script>
</head>
<body> </body>
</html>

obj01

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script language="javascript" type="text/javascript">
var person = { name: "wyp", age: 32 };
person.sex = true;
window.alert(person.name); </script>
</head>
<body> </body>
</html>

obj02

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script language="javascript" type="text/javascript">
//var obj1 = { name: 'wyp' };
//var obj2 = obj1;
//window.alert(obj2.name);
//obj1.name = "wangyunpeng";
//window.alert(obj2.name); var obj = { name: "ddd" }; </script>
</head>
<body> </body>
</html>

obj03

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script language="javascript" type="text/javascript">
//var person = new Object();
//person.name = 'wyp';
//person.age = 33;
//person.say = function () {
// window.alert(this.name);
//}
//person.say(); var person = {
name: "wyp",
age: 33,
say: function () {
window.alert(this.name);
}
}
person.say();
</script>
</head>
<body> </body>
</html>

obj04

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script language="javascript" type="text/javascript">
var Person = function () { }; var person = new Person();
window.alert(person instanceof Person);
</script>
</head>
<body> </body>
</html>

obj05

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script language="javascript" type="text/javascript">
function Person(name ,age) {
this.name = name;
this.age = age;
this.say = function () {
window.alert(this.name);
}
}
var person1 = new Person("wyp", 33);
var person2 = new Person("hg", 29);
window.alert(person1.say == person2.say);//false person1.say = function () {
window.alert(this.age);
}
person1.say(); person2.say(); </script>
</head>
<body> </body>
</html>

obj06

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script language="javascript" type="text/javascript">
function Person() { }
Person.prototype.name = "wyp";
Person.prototype.age = 33;
Person.prototype.say = function () {
window.alert(this.name);
} var person1 = new Person();
var person2 = new Person();
person2.name = "hg";
person2.age = 29;
person1.say();
person2.say();
</script>
</head>
<body> </body>
</html>

obj07

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script language="javascript" type="text/javascript">
function Person() { }
Person.prototype = {
constructor: Person,
name: "wyp",
age: 33,
works: ['gh', 'zyx'],
say: function () {
window.alert(this.name + ",[" + this.works + "]");
}
};
var person1 = new Person();
person1.name = "wyp";
person1.works.push("db");
person1.say(); var person2 = new Person();
person2.name = "sl";
person2.say(); </script>
</head>
<body> </body>
</html>

obj08

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script language="javascript" type="text/javascript">
function Person(name, age, works) {
this.name = name;
this.age = age;
this.works = works;
if (!Person.prototype.say) {
Person.prototype.say = function () {
window.alert(this.name + ",[" + this.works + "]");
}
}
} var person1 = new Person("wyp", 33, ['hg', 'zyx']);
person1.works.push('db');
//person1.say = function () {
// window.alert(this.age);
//};
var person2 = new Person("gh", 29, ['hg', 'zyx']); person1.say();
person2.say(); window.alert(person1.say == person2.say);
</script>
</head>
<body> </body>
</html>

obj09

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script language="javascript" type="text/javascript">
//function Person(name, age) {
// this.name = name;
// this.age = age;
// this.say = say;
//} function Person() { } Person.prototype.name = "name";
Person.prototype.age = 33;
Person.prototype.say = function () {
window.alert(this.name);
} function say() {
window.alert(this.name);
} var person1 = new Person("wyp", 33);
person1.name = "wyp";
person1.say = function () {
window.alert(this.age);
}
var person2 = new Person("gh", 29);
window.alert("person1.say == person2.say:" + (person1.say == person2.say)); window.alert("prototype.isPrototypeOf:" + Person.prototype.isPrototypeOf(person1)); window.alert("constructor:" + (person1.constructor == Person)); window.alert("name:" + person1.hasOwnProperty("name")); //delete person1.name;
//window.alert("name:" + person1.hasOwnProperty("name")); window.alert(" [in] " + ("name" in person1)); function isPrototypeProperty(obj,prop) {
return (!(obj.hasOwnProperty(prop)) && (prop in obj));
}
</script>
</head>
<body> </body>
</html>

obj10

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script language="javascript" type="text/javascript">
( function (num) {
for (var i = 0; i < num; i++) { }
} )(20);
window.alert(i);
</script>
</head>
<body> </body>
</html>

close01

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script language="javascript" type="text/javascript">
function Parent() {
this.pv = "parent";
} Parent.prototype.showParent = function () {
window.alert(this.pv);
} function Child() {
this.cv = "child";
} Child.prototype = new Parent(); Child.prototype.showChild = function () {
window.alert(this.cv);
} var child= new Child();
//window.alert(child.pv);
child.showParent();
child.showChild(); </script>
</head>
<body> </body>
</html>

jicheng01

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script language="javascript" type="text/javascript">
function Parent(name) {
this.color = ['red', 'blue'];
this.name = name;
this.say = say;
}
function say() {
window.alert(this.name);
} function Child(name, age) {
this.age = age;
Parent.call(this, name);
} var child1 = new Child("wyp", 33);
//child1.color.push("yellow");
//window.alert(child1.color);
//window.alert(child1.name);
//window.alert(child1.age);
var child2 = new Child("meinv", 23);
//window.alert(child1.name + "," + child1.age);
//window.alert(child2.name + "," + child2.age);
child1.say = function () {
window.alert(child1.age);
}
child1.say();
child2.say();
</script>
</head>
<body> </body>
</html>

jicheng02

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script language="javascript" type="text/javascript">
function Parent(name) {
this.name = name;
if(!Parent.prototype.say){
Parent.prototype.say = function () {
window.alert(this.name);
};
}
}
//Parent.prototype = {}; function Child(name, age) {
this.age = age;
Parent.call(this, name);
} Child.prototype = new Parent(); //重写父类say方法
//Child.prototype.say = function () {
// window.alert(this.name + "," + this.age);
//}; var child1 = new Child("wyp", 33);
child1.say(); </script>
</head>
<body> </body>
</html>

jicheng03

javascript中function和object的区别,以及javascript如何实现面向对象的编程思想.的更多相关文章

  1. JavaScript之Function 和 Object 的区别和联系

    1.先看一个控制台的输出: instanceof 运算符字面意思是 左边是右边的一个实例吗? 但是这两条输出让人很困惑.Function 是 Object 的实例.Object 也是 Function ...

  2. javascript中Function与Object

    1. 先来一段代码: console.log(Function); // function Function() { [native code] } console.log(Object); // f ...

  3. Javascript中Function,Object,Prototypes,__proto__等概念详解

    http://anykoro.sinaapp.com/2012/01/31/javascript%E4%B8%ADfunctionobjectprototypes__proto__%E7%AD%89% ...

  4. JavaScript中:表达式和语句的区别

    JavaScript中:表达式和语句的区别 Javascript语言精粹:表达式是由运算符构成,并运算产生结果的语法结构.程序是由语句构成,语句则是由“:(分号)”分隔的句子或命令.如果在表达式后面加 ...

  5. Python中type与Object的区别

    Python中type与Object的区别 在查看了Python的API后,总算明白了.现在总结如下: 先来看object的说明: Python中关于object的说明很少,甚至只有一句话: clas ...

  6. 转载 javascript中(function($){...})(jQuery)写法是什么意思

    javascript中(function($){...})(jQuery)写法是什么意思   这里实际上是匿名函数function(arg){...}这就定义了一个匿名函数,参数为arg 而调用函数 ...

  7. javascript中 (function(){})();如何理解?

    javascript中 (function(){})();如何理解? javascript中: (function(){})()是匿名函数,主要利用函数内的变量作用域,避免产生全局变量,影响整体页面环 ...

  8. JavaScript中Function函数与Object对象的关系

    函数对象和其他内部对象的关系 除了函数对象,还有很多内部对象,比如:Object.Array.Date.RegExp.Math.Error.这些名称实际上表示一个 类型,可以通过new操作符返回一个对 ...

  9. JavaScript中Function原型及其prototype属性的简单应用

    大家都知道在JavaScript中是没有类的概念的,但是却是有对象的概念的.有的人可能理解对象和类有些迷糊,这里简单的概括一下他们之间的区别: 类:抽象的概念,例如人,动物,汽车等都可以抽象成一个类 ...

随机推荐

  1. 支持5G-WiFi的安卓设备搜索不到5G信号解决方法

    安卓设备必须获得root权限,然后修改 /system/etc/wifi/nvram_net.txt 文件, 将ccode = CN 改为 ccode = ALL.保存并重启即可. 三星EK-GC11 ...

  2. Binary Tree Inorder Traversal leetcode java

    题目: Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binar ...

  3. SonarQube代码质量管理平台 的安装、配置与使用

    SonarQube是管理代码质量一个开放平台,可以快速的定位代码中潜在的或者明显的错误,下面将会介绍一下这个工具的安装.配置以及使用. 准备工作: 1.jdk(不再介绍) 2.sonarqube:ht ...

  4. 如何监控执行的SQL语句?

    环境: SQL Server 2012. 打开SQL Server Profiler. 在菜单中选择New Trace, 连接上SQL Server. 在弹出的窗口中选择Event selection ...

  5. Bootstrap3免费单页面模板-Shuffle

    在线演示 本地下载 这是一款当前最热门的模板,单页面模板现在越来越时兴,它简洁的页面和每一次滑动都带来的全新视角.非常值得收藏和使用!

  6. C#.NET常见问题(FAQ)-abstract抽象类如何理解

    例如有太多相似,但是不一样的类,他们都继承自同一个基类(比如大型游戏有各个种族,每个种族有各种人物,加起来几百种类型,然后基本上他们都是一个角色,都有基本相同的属性和方法,比如都会走,只是速度不同,都 ...

  7. windows系统上安装Redis,并且设置Redis密码

    一.Windows版本的Redis下载 下载地址:https://github.com/MSOpenTech/redis/releases 我下载的是最新版的3.2 二.安装Redis 我下载的是安装 ...

  8. ZH奶酪:putty远程登录Linux服务器非常慢

    11.pytty远程登录Linux服务器非常慢 http://www.it165.net/os/html/201209/3425.html 12.启动SSHD服务报错 http://blog.chin ...

  9. wepy - 与原生有什么不同(事件更改)

    对于repeat,详情见官方文档 <style lang="less"> .userinfo { display: flex; flex-direction: colu ...

  10. Mapreduce实例-分组排重(group by distinct)

    public class GroupComparator implements RawComparator<MyBinaryKey> { @Override public int comp ...