Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
0
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<p>Hello, world.</p>
</body>
</html>
// var Outer = function () {
// console.log("before innder constructor");
// var innder = function () {
// console.log("init innder constructor");
// };
// console.log("after innder constructor");
// console.log("before A");
// innder.a ="A";
// innder.b = function() { console.log(this, "hi");};
// console.log("after A");
// return innder; // 如果没有return 返回的是空对像
// };
// // temp now just a function
// // new 只是做了个新对象出来,否则直接调用构造函数会影响执行上下文,使之变成window
// var temp = new Outer();
// console.dir(new temp());
/*****************************************************/
var Person = new Class();
console.log(Person());
console.log( typeof Person, Person.a,typeof Person);
var Class = function () {
var klass = function () {
this.init.apply ( this, arguments);
};
klass.prototype.init = function () {};
klass.fn = klass.prototype;
klass.fn.parent = klass;
klass.extend = function (obj){
var extended = obj.extended;
for( var i in ojb) {
klass[i] = obj[i];
}
if(extended) extended(extended);
};
klass.include = function (obj) {
var included = obj.included;
for ( var i in included) {
klass.fn[i] = obj[i];
}
if (included) included(klass);
};
return klass;
};
var Person = new Class();
console.log(Person());
console.log( typeof Person, Person.a,typeof Person);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.