`
axgle
  • 浏览: 94181 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

Javascript.new

阅读更多
In firefox, make Javascript.new like Ruby.new
Object.prototype['new']=function(){
    var params=[];
    var argc=arguments.length;
    for(var i=0;i<argc;i++){
        params.push('arguments['+i+']');
    }
    var code='return new this('+params.join(',')+');';
    return new Function(code).apply(this,arguments);
}

Number.new(100);//100
String.new("text");//"text"
Array.new(1,2,3);//[1,2,3]

function Person(name){
    this.name=name;
    this.toString=function(){return this.name;}
}
tom=Person.new('Tom');
joy=Person.new('Joy');
tom+" and "+joy;


with ExtJS,you can use it like this:
Ext.Window.new({height:100, width:200}).show();
分享到:
评论
2 楼 axgle 2009-06-30  
just for fun.
1 楼 hackwaly 2009-06-29  
new是关键字和保留字,这么用符合ecma262标准么?

相关推荐

    javascript.the.definitive.guide.5th.2006(英文版)

    This book is both an example-driven programmer's guide and a keep-on-your-desk reference, with new chapters that explain everything you need to know to get the most out of JavaScript, including: ...

    new.riders.press.ppk.on.javascript.sep.2006.rar

    《PPK on JavaScript》是由Peter-Paul Koch(PPK)撰写的一本关于JavaScript的书籍,出版于2006年9月,由New Riders Press发行。这本书深入浅出地探讨了JavaScript这一重要的Web开发语言,涵盖了从基础到高级的各种...

    Mastering.JavaScript.1785281348

    However, the JavaScript landscape has changed dramatically in recent years, and you need to adapt to the new world of JavaScript that people now expect. Mastering modern JavaScript techniques and the...

    javascript高级编程JavaScript.pdf

    JavaScript,作为一种广泛应用于Web开发的脚本语言,其在实际应用中常常会遇到命名冲突的问题。特别是在大型项目中,随着代码量的增加,不同模块之间的函数或变量名称可能相同,导致错误。为了解决这个问题,开发者...

    Beginning.JavaScript.5th.Edition

    This new edition has been extensively updated to reflect the way JavaScript is most commonly used today, introducing you to the latest tools and techniques available to JavaScript developers....

    Javascript.Object.Oriented.Programming.pdf

    You should read through this course if you want to be able to take your JavaScript skills to a new level of sophistication. Style and approach This course is a comprehensive guide where each chapter...

    Android调用JavaScript.zip

    在Android应用开发中,有时我们需要实现Android原生代码与JavaScript之间的交互,这通常涉及到WebView组件的使用。"Android调用JavaScript.zip"这个压缩包可能包含了关于如何在Android中调用JavaScript代码的相关...

    JavaScript.The.Definitive.Guide

    This book is both an example-driven programmer's guide and a keep-on-your-desk reference, with new chapters that explain everything you need to know to get the most out of JavaScript, including: ...

    Functional.Programming.in.JavaScript.2016.6.pdf

    In complex web applications, the low-level details of your JavaScript code can obscure the workings of the system as a whole. As a coding style, functional programming (FP) promotes loosely coupled ...

    Packt.Object-Oriented.JavaScript.3rd.Edition

    the new features added in ES6 Find out about ECMAScript 6’s Arrow functions, and make them your own Understand objects in Google Chrome developer tools and how to use Them Use a mix of prototypal ...

    调用JavaScript.zip

    webView.evaluateJavascript("javascript:yourFunction()", new ValueCallback() { @Override public void onReceiveValue(String value) { // 处理JavaScript的返回值 } }); ``` 4. **注入JavaScript代码**...

    (JavaScript.Patterns).Stoyan.Stefanov.文字版

    4. **构造函数与new关键字**:构造函数用于创建特定类型的对象,而`new`关键字则是用来调用构造函数并创建新实例的关键。使用构造函数可以实现类的抽象,为对象实例化提供模板。 5. **模块模式**:为了管理代码的...

    精通JavaScript.pdf

    var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("demo").innerHTML = this.responseText; } }...

    安卓Android源码——安卓Android调用JavaScript.rar

    在安卓(Android)平台上,与JavaScript的交互是一个常见的需求,特别是在开发混合应用或者利用Web技术增强原生应用功能时。本资源"安卓Android源码——安卓Android调用JavaScript.rar"显然是一个关于如何在Android...

    ethers-new-JavaScript.zip

    JavaScript(和TypeScript)中完整的以太坊钱包实现和实用程序。 特征: 将您的私钥安全,可靠地保存在客户端中 导入和导出JSON钱包(Geth,奇偶校验和众筹) 导入和导出BIP 39个助记词短语(12个单词备用短语)和...

Global site tag (gtag.js) - Google Analytics